Skip to content
This repository was archived by the owner on Jun 22, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 10 additions & 23 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
{
"presets": [
presets: [
["@babel/preset-react"],
[
"env",
'@babel/preset-env',
{
"modules": false,
"targets": {
"browsers": "> 1%",
"uglify": true
},
"useBuiltIns": true
targets: {
node: 'current'
}
}
],
"react"
]
],
"plugins": [
"syntax-dynamic-import",
[ "transform-class-properties", { "spec": true } ]
],
"env": {
"test": {
"presets": [ [ "env" ], "react" ],
"plugins": [
"syntax-dynamic-import",
[ "transform-class-properties", { "spec": true } ]
]
}
}
plugins: [
'@babel/plugin-proposal-class-properties'
]
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v13.11.0
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ before_install:
- chmod +x ./cc-test-reporter
- cp env-example .env
install:
- bundle install
- nvm install
- npm i -g yarn
- yarn install
- bundle install
script:
- yarn test
- RAILS_ENV=test bundle exec rake db:create db:migrate
Expand Down
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM ruby:2.5.3

RUN curl -sL https://deb.nodesource.com/setup_13.x | bash - && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && \
apt-get install -qq -y build-essential graphviz nodejs wait-for-it yarn \
libpq-dev \
postgresql-client \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/app

COPY Gemfile Gemfile.lock package.json yarn.lock ./

RUN yarn install
RUN bundle install

COPY . .
COPY ./config/database.docker-compose.yml ./config/database.yml

# CMD ["bundle", "exec", "rails", "server"]
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ rbenv install < .ruby-version
```
brew install postgresql
```
* Install Graphviz
Graphviz is a requirement of Rails ERD.
Follow the instructions here <https://voormedia.github.io/rails-erd/install.html>
* Start PostgreSQL on startup
```
brew services start postgresql
Expand Down Expand Up @@ -61,6 +64,41 @@ bundle exec rake db:seed
bundle exec rails server
```

## Docker

* Replace the development section in `config/database.yml` with:

```yaml
development:
<<: *default
database: PresenceChecker_development
host: db
username: postgres
password:
```

Note: password is deliberately blank.

* Build the containers

```bash
docker-compose build
```

* Initialize the database

```bash
docker-compose run web bundle exec rake db:create
docker-compose run web bundle exec rake db:migrate
docker-compose run web bundle exec rake db:seed
```

* Start the app

```bash
docker-compose up
```

## Deployment

Deployments happen automatically (performed by TravisCI) when code is merged into the `master` branch.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { firstCharCap } from '../../../utilities/utilities';

import Table from '../../../components/Table';

import { legacyParse, convertTokens } from "@date-fns/upgrade/v2";

export default class MovementsTable extends React.Component {
static propTypes = {
movements: PropTypes.array,
Expand Down Expand Up @@ -35,7 +37,7 @@ export default class MovementsTable extends React.Component {
<h3 className="is-dark">{firstCharCap(item.direction)}</h3>
</td>
<td className="has-bottom-border has-right-border">
{format(item.carrier_date_time, 'DD MMM YYYY')}
{format(legacyParse(item.carrier_date_time), convertTokens('DD MMM YYYY'))}
</td>
<td className="has-bottom-border">
{item.visa_type}
Expand Down
11 changes: 8 additions & 3 deletions app/javascript/bundles/Presence/components/PresenceDates.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React from 'react';
import DatePicker from 'react-datepicker';
import { format, addDays } from 'date-fns';

import { legacyParse, convertTokens } from "@date-fns/upgrade/v2";

export default class PresenceDates extends React.Component {
static propTypes = {
isEligible: PropTypes.bool,
Expand Down Expand Up @@ -43,9 +45,12 @@ export default class PresenceDates extends React.Component {
highlightDates,
loading,
} = this.props;
const selected = addDays(endOfRollingYear, 1)
const date = format(selected, 'D MMMM YYYY');

let selected;
let date;
if (endOfRollingYear) {
selected = addDays(legacyParse(endOfRollingYear), 1)
date = format(legacyParse(selected), convertTokens('D MMMM YYYY'));
}
let stateClass = '';

if (loading) {
Expand Down
12 changes: 10 additions & 2 deletions app/javascript/bundles/Presence/components/PresenceTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { sum, map } from 'lodash';
import Year from './Year';
import { format, subYears, addDays } from 'date-fns';

import { legacyParse, convertTokens } from "@date-fns/upgrade/v2";

export default class PresenceTable extends React.Component {
static propTypes = {
isEligible: PropTypes.bool,
Expand Down Expand Up @@ -39,12 +41,18 @@ export default class PresenceTable extends React.Component {

startDate = yearNum => {
const { endOfRollingYear } = this.props;
return format(addDays(subYears(endOfRollingYear, yearNum), 1), 'DD MMM YYYY');
return format(
legacyParse(addDays(legacyParse(subYears(legacyParse(endOfRollingYear), yearNum)), 1)),
convertTokens('dd mm yyyy')
);
};

endingDate = yearNum => {
const { endOfRollingYear } = this.props;
return format(subYears(endOfRollingYear, yearNum - 1), 'DD MMM YYYY');
return format(
legacyParse(subYears(legacyParse(endOfRollingYear), yearNum - 1)),
convertTokens('dd mm yyyy')
);
};

render() {
Expand Down
4 changes: 3 additions & 1 deletion app/javascript/components/PresenceDebugger.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { format } from 'date-fns';

import TimePeriod from './TimePeriod';

import { legacyParse, convertTokens } from "@date-fns/upgrade/v2";

export default class DaysPresent extends React.Component {
static propTypes = { days_present: PropTypes.object };
// "days_present": {
Expand Down Expand Up @@ -37,7 +39,7 @@ export default class DaysPresent extends React.Component {
return (
<TimePeriod
key={key}
periodName={format(key, 'MMMM YYYY')}
periodName={format(legacyParse(key), convertTokens('MMMM YYYY'))}
days={days}
/>
);
Expand Down
4 changes: 3 additions & 1 deletion app/javascript/components/TimePeriod.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import React from 'react';

import Table from './Table';

import { legacyParse, convertTokens } from "@date-fns/upgrade/v2";

export default class TimePeriod extends React.Component {
static propTypes = {
periodName: PropTypes.string,
Expand All @@ -23,7 +25,7 @@ export default class TimePeriod extends React.Component {
{days.map(({ fullDate, inNZ }) => {
return (
<td key={fullDate} className={inNZ ? 'is-in-country' : ''}>
{format(fullDate, 'DD')}
{format(legacyParse(fullDate), convertTokens('DD'))}
</td>
);
})}
Expand Down
22 changes: 12 additions & 10 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactOnRails from 'react-on-rails';
import { format, eachDay, addDays, subDays } from 'date-fns';
import { format, eachDayOfInterval, addDays, subDays } from 'date-fns';
import 'isomorphic-fetch';

import { getCSRF, databaseURL } from '../utilities/utilities';
Expand All @@ -10,11 +10,13 @@ import PresenceDates from '../bundles/Presence/components/PresenceDates';
import PresenceTable from '../bundles/Presence/components/PresenceTable';
import MovementsTable from '../bundles/Presence/components/MovementsTable';

import { legacyParse, convertTokens } from "@date-fns/upgrade/v2";

export default class ShowClient extends React.Component {
state = {
loading: false,
backgroundLoading: false,
endOfRollingYear: subDays(new Date(), 1),
endOfRollingYear: subDays(legacyParse(new Date()), 1),
meetsMinimumPresence: false,
meetsFiveYearPresence: false,
daysInNZ: {},
Expand All @@ -28,7 +30,7 @@ export default class ShowClient extends React.Component {

checkEndOfRollingYear = endOfRollingYear => {
const { databaseId } = this.props;
const formattedDate = format(endOfRollingYear, 'YYYY-MM-DD');
const formattedDate = format(legacyParse(endOfRollingYear), convertTokens('yyyy-mm-dd'));
const url = `${databaseURL()}/clients/${databaseId}/eligibility/${formattedDate}`;

this.setState({
Expand All @@ -48,7 +50,7 @@ export default class ShowClient extends React.Component {
return result.json();
})
.then(response =>
this.onDataResponse(response[format(endOfRollingYear, 'YYYY-MM-DD')])
this.onDataResponse(response[format(legacyParse(endOfRollingYear), convertTokens('yyyy-mm-dd'))])
)
.catch(error => {
console.error('Server error:', error);
Expand All @@ -59,7 +61,7 @@ export default class ShowClient extends React.Component {
};

onDateChange = date => {
let endOfRollingYear = subDays(new Date(date), 1)
let endOfRollingYear = subDays(legacyParse(new Date(date)), 1)

this.setState({
endOfRollingYear,
Expand All @@ -84,18 +86,18 @@ export default class ShowClient extends React.Component {
checkNextWeek = () => {
const { databaseId } = this.props;
const { endOfRollingYear } = this.state;
const nextWeek = eachDay(
addDays(endOfRollingYear, 1),
addDays(endOfRollingYear, 8)
);
const nextWeek = eachDayOfInterval({
start: addDays(legacyParse(endOfRollingYear), 1),
end: addDays(legacyParse(endOfRollingYear), 8)
});
let loadingNumber = nextWeek.length;

this.setState({
backgroundLoading: true,
});

for (let day = 0, l = loadingNumber; day < l; day++) {
const formattedDate = format(nextWeek[day], 'YYYY-MM-DD');
const formattedDate = format(legacyParse(nextWeek[day]), convertTokens('yyyy-mm-dd'));
const url = `${databaseURL()}/clients/${databaseId}/eligibility/${formattedDate}`;

fetch(url, {
Expand Down
61 changes: 61 additions & 0 deletions config/database.docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# PostgreSQL. Versions 9.1 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
<<: *default
database: PresenceChecker_development
host: db
username: postgres
password:

test:
<<: *default
database: PresenceChecker_test
host: db
username: postgres
password:

# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: PresenceChecker_production
username: PresenceChecker
password: <%= ENV['PRESENCECHECKER_DATABASE_PASSWORD'] %>
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Rails.application.configure do
# Verifies that versions and hashed value of the package contents in the project's package.json
config.webpacker.check_yarn_integrity = true
config.webpacker.check_yarn_integrity = false
# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded on
Expand Down
Loading