Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/e-picsa/picsa-apps into ft-…
Browse files Browse the repository at this point in the history
…budget-detailed-summary
  • Loading branch information
OchiengPaul442 committed Jan 17, 2024
2 parents 3191518 + 1260de1 commit 47e1ded
Show file tree
Hide file tree
Showing 44 changed files with 1,530 additions and 822 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/web-release-dashboard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Deploy dashboard to vercel hosting
# https://vercel.com/guides/how-can-i-use-github-actions-with-vercel

# Required Secrets
# - VERCEL_TOKEN
# - VERCEL_PROJECT_ID
# - VERCEL_ORG_ID

name: Web Release Dashboard

# Only keep one active build per ref (e.g. pr branch, push branch, triggering workflow ref)
concurrency:
group: web-release-dashboard-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'apps/picsa-apps/dashboard/**'

jobs:
web_release_dashboard:
runs-on: ubuntu-latest
environment: dashboard
steps:
- uses: actions/checkout@v3
with:
lfs: true
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
#############################################################################
# Node Modules
# Manually restore any previous cache to speed install
# As immutable install will not change cache only save new cache if not hit
# Uses fine-grained methods from https://github.com/actions/cache
#############################################################################
- uses: actions/cache/restore@v3
id: cache
with:
path: ./.yarn/cache
key: ${{ runner.os }}-node-modules-yarn-v1-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-modules-yarn-v1-
- name: Install node modules
run: yarn install --immutable && npm i -g vercel

- uses: actions/cache/save@v3
if: steps.cache.outputs.cache-hit != 'true'
with:
path: ./.yarn/cache
key: ${{ runner.os }}-node-modules-yarn-v1-${{ hashFiles('yarn.lock') }}

- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}

# Required build script defined in dashboard project `vercel.json`
- name: Build
run: npx vercel --local-config apps/picsa-apps/dashboard/vercel.json build --prod --token=${{ secrets.VERCEL_TOKEN }}

- name: Deploy
run: npx vercel --local-config apps/picsa-apps/dashboard/vercel.json deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}

# TODO - run supabase db migrations (if required)
# TODO - handle staging/preview deploy (if required)

# NOTE - could also use deployment action to populate additonal metadata (could use cli)
# https://github.com/marketplace/actions/vercel-action

# - uses: amondnet/vercel-action@v20
# with:
# vercel-token: ${{ secrets.VERCEL_TOKEN }}
# github-token: ${{ secrets.GITHUB_TOKEN }}
# vercel-args: '--local-config=apps/picsa-apps/dashboard/vercel.json --prebuilt --prod'
# vercel-org-id: ${{ secrets.VERCEL_ORG_ID}}
# vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID}}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ apps/extension-toolkit/www_sourcemaps
.next/

.eslintcache
.nx/cache
.nx/cache
.vercel
8 changes: 7 additions & 1 deletion apps/picsa-apps/dashboard/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
"maximumError": "2mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"fileReplacements": [
{
"replace": "libs/environments/src/environment.ts",
"with": "libs/environments/src/environment.prod.ts"
}
],
"outputHashing": "all"
},
"development": {
Expand Down
14 changes: 14 additions & 0 deletions apps/picsa-apps/dashboard/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"buildCommand": "yarn nx run picsa-apps-dashboard:build:production",
"installCommand": "yarn install",
"outputDirectory": "dist/apps/picsa-apps/dashboard/browser",
"github": {
"enabled": false
},
"rewrites": [
{
"source": "/(.*)",
"destination": "/index.html"
}
]
}
2 changes: 0 additions & 2 deletions apps/picsa-server/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

**Misc**

- Update legacy docs

- Drop additional kobo_sync columns no longer used (not permanent store of kobo metadata)

- Consider calling proxy directly from app (essentially two separate sync protocols)
Expand Down
4 changes: 4 additions & 0 deletions apps/picsa-server/supabase/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@

.env
.env.local

# Supabase
.branches
.temp
2 changes: 1 addition & 1 deletion apps/picsa-server/supabase/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ port = 54329
# Configure one of the supported pooler modes: `transaction`, `session`.
pool_mode = "transaction"
# How many server connections to allow per user/database pair.
default_pool_size = 15
default_pool_size = 20
# Maximum number of client connections allowed.
max_client_conn = 100

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

CREATE EXTENSION IF NOT EXISTS "pgsodium" WITH SCHEMA "pgsodium";

CREATE EXTENSION IF NOT EXISTS "pg_graphql" WITH SCHEMA "graphql";

CREATE EXTENSION IF NOT EXISTS "pg_stat_statements" WITH SCHEMA "extensions";

CREATE EXTENSION IF NOT EXISTS "pgcrypto" WITH SCHEMA "extensions";

CREATE EXTENSION IF NOT EXISTS "pgjwt" WITH SCHEMA "extensions";

CREATE EXTENSION IF NOT EXISTS "supabase_vault" WITH SCHEMA "vault";

CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA "extensions";

REVOKE USAGE ON SCHEMA "public" FROM PUBLIC;
GRANT USAGE ON SCHEMA "public" TO "postgres";
GRANT USAGE ON SCHEMA "public" TO "anon";
GRANT USAGE ON SCHEMA "public" TO "authenticated";
GRANT USAGE ON SCHEMA "public" TO "service_role";

ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "postgres";
ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "anon";
ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "authenticated";
ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "service_role";

ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "postgres";
ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "anon";
ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "authenticated";
ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "service_role";

ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "postgres";
ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "anon";
ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "authenticated";
ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "service_role";

RESET ALL;
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnIni
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatStepper } from '@angular/material/stepper';
import { ActivatedRoute, Router } from '@angular/router';
import { MONTH_NAMES } from '@picsa/data';
import { ANIMATION_DELAYED, FadeInOut } from '@picsa/shared/animations';
import { map, Subject, switchMap, takeUntil } from 'rxjs';

import { IBudgetMeta, IEnterpriseScaleLentgh } from '../../models/budget-tool.models';
import { IBudgetCard } from '../../schema';
import { BudgetStore } from '../../store/budget.store';
import { BudgetCardService } from '../../store/budget-card.service';
import { MONTHS, PERIOD_DATA_TEMPLATE } from '../../store/templates';
import { PERIOD_DATA_TEMPLATE } from '../../store/templates';

@Component({
selector: 'budget-create',
Expand All @@ -26,7 +27,7 @@ export class BudgetCreatePage implements OnInit, OnDestroy {
filteredEnterprises: IBudgetCard[] = [];
periodScaleOptions: IEnterpriseScaleLentgh[] = ['weeks', 'months'];
periodTotalOptions = new Array(12).fill(0).map((v, i) => i + 1);
periodLabelOptions = [...MONTHS];
periodLabelOptions = [...MONTH_NAMES.map((m) => m.labelShort)];
enterpriseTypeCards: IBudgetCard[] = [];
private componentDestroyed$ = new Subject<boolean>();
@ViewChild('stepper', { static: true }) stepper: MatStepper;
Expand Down
10 changes: 6 additions & 4 deletions apps/picsa-tools/budget-tool/src/app/store/budget.store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable, OnDestroy } from '@angular/core';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
import { ConfigurationService, IConfiguration } from '@picsa/configuration';
import { MONTH_NAMES } from '@picsa/data';
import { APP_VERSION } from '@picsa/environments';
import { IAppMeta } from '@picsa/models';
import { PicsaDialogService } from '@picsa/shared/features';
Expand All @@ -9,7 +10,7 @@ import { generateID } from '@picsa/shared/services/core/db/db.service';
import { PrintProvider } from '@picsa/shared/services/native/print';
import merge from 'deepmerge';
import { toJS } from 'mobx';
import { action, computed, observable } from 'mobx-angular';
import { action, observable } from 'mobx-angular';
import { BehaviorSubject, Subject, takeUntil } from 'rxjs';

import {
Expand All @@ -22,9 +23,9 @@ import {
IBudgetValueCounters,
IBudgetValueScale,
} from '../models/budget-tool.models';
import { IBudgetCard, IBudgetCardGrouping, IBudgetCardWithValues } from '../schema';
import { IBudgetCard, IBudgetCardWithValues } from '../schema';
import { checkForBudgetUpgrades } from '../utils/budget.upgrade';
import { MONTHS, NEW_BUDGET_TEMPLATE, PERIOD_DATA_TEMPLATE } from './templates';
import { NEW_BUDGET_TEMPLATE, PERIOD_DATA_TEMPLATE } from './templates';

type IBudgetCounter = 'large' | 'large-half' | 'medium' | 'medium-half' | 'small' | 'small-half';
export type IBudgetCounterSVGIcons = Record<IBudgetCounter, SafeResourceUrl>;
Expand Down Expand Up @@ -377,6 +378,7 @@ export class BudgetStore implements OnDestroy {
// create list of labels depending on scale, total and start, e.g. ['week 1','week 2'] or ['Sep','Oct','Nov']
private generatePeriodLabels(meta: IBudgetMeta): string[] {
const { lengthScale, lengthTotal, monthStart = 1 } = meta;
const months = MONTH_NAMES.map((m) => m.labelShort);
if (lengthScale === 'weeks') {
return new Array(lengthTotal).fill(0).map((_, i) => 'Week ' + (i + 1));
}
Expand All @@ -385,7 +387,7 @@ export class BudgetStore implements OnDestroy {
}
if (lengthScale === 'months') {
// duplicate array so that can still slice up to 12 months from dec
const base = [...MONTHS, ...MONTHS];
const base = [...months, ...months];
return base.slice(monthStart - 1, lengthTotal + monthStart - 1);
}
return [];
Expand Down
2 changes: 0 additions & 2 deletions apps/picsa-tools/budget-tool/src/app/store/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,3 @@ export const BUDGET_PERIOD_ROWS: IBudgetPeriodRow[] = [
{ type: 'outputs', label: translateMarker('Outputs'), sublabel: translateMarker('For Sale') },
{ type: 'produceConsumed', label: translateMarker('Produce Consumed') },
];

export const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { Injectable } from '@angular/core';
import { MONTH_NAMES } from '@picsa/data';
import type { IChartConfig, IChartId, IChartMeta, IStationData, IStationMetaDB } from '@picsa/models';
import { PicsaChartComponent } from '@picsa/shared/features/charts/chart';
import { PicsaTranslateService } from '@picsa/shared/modules';
Expand Down Expand Up @@ -47,6 +48,9 @@ export class ClimateChartService {

private pointRadius = 8;

/** List of month names translated */
private monthNames: string[] = [];

constructor(
private translateService: PicsaTranslateService,
private dataService: ClimateDataService,
Expand All @@ -69,6 +73,8 @@ export class ClimateChartService {
this.station = station;
this.station$.next(station);
this.stationData = station?.data || [];
// ensure month names are translated
this.monthNames = await this.translateService.translateArray(MONTH_NAMES.map((m) => m.labelShort));
return this.station;
}

Expand Down Expand Up @@ -349,7 +355,7 @@ export class ClimateChartService {

private _formatYAxis(value: number, meta: IChartMeta, isAxisLabel?: boolean) {
const { yMajor } = meta;
const { monthNames } = this.translateService;

let label: string;
switch (meta.yFormat) {
case 'date-from-July': {
Expand All @@ -359,15 +365,15 @@ export class ClimateChartService {
if (isAxisLabel) {
const monthNumber = Math.round(dayNumber / yMajor) % 12;
// just want nearest month name
label = monthNames[monthNumber].substring(0, 3);
label = this.monthNames[monthNumber];
} else {
//simply converts number to day rough date value (same method as local met office)
//initialise year from a year with 365 days
const d = new Date(2015, 0);
d.setDate(dayNumber);

// just take first 3 letters
label = `${d.getDate()}-${monthNames[d.getMonth() % 12].substring(0, 3)}`;
label = `${d.getDate()}-${this.monthNames[d.getMonth() % 12]}`;
}
return label;
}
Expand Down
7 changes: 6 additions & 1 deletion apps/picsa-tools/seasonal-calendar-tool/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
"tsConfig": "apps/picsa-tools/seasonal-calendar-tool/tsconfig.app.json",
"assets": [
"apps/picsa-tools/seasonal-calendar-tool/src/favicon.ico",
"apps/picsa-tools/seasonal-calendar-tool/src/assets"
"apps/picsa-tools/seasonal-calendar-tool/src/assets",
{
"glob": "*.json",
"input": "libs/i18n/assets",
"output": "assets/i18n"
}
],
"styles": ["apps/picsa-tools/seasonal-calendar-tool/src/styles.scss", "libs/theme/src/_index.scss"],
"scripts": []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<div class="table-container">
<h2 class="dialog-title">Add Activity</h2>
<h2 class="dialog-title">{{'Add Activity' | translate}}</h2>
<div class="dialog-body">
<mat-form-field>
<mat-label>Select Activity</mat-label>
<mat-label>{{'Select Activity' | translate}}</mat-label>
<mat-select class="selectField" [(ngModel)]="selectedActivity">
<mat-option *ngFor="let activity of activities" [value]="activity">
{{ activity }}
</mat-option>
</mat-select>
</mat-form-field>
<div *ngIf="selectedActivity === 'Other'">
<h4>Type other activity</h4>
<h4>{{'Type other activity' | translate}}</h4>
<input matInput class="inputField" placeholder="Custom Activity" [(ngModel)]="customActivity">
</div>
</div>
<div class="buttons">
<button mat-button class="add-button" (click)="onSave()" [mat-dialog-close]="selectedActivity || customActivity" [disabled]="!(selectedActivity || customActivity)">Add</button>
<button mat-button class="cancel-button" (click)="onClose()">Cancel</button>
<button mat-button class="add-button" (click)="onSave()" [mat-dialog-close]="selectedActivity || customActivity" [disabled]="!(selectedActivity || customActivity)">{{'Add' | translate}}</button>
<button mat-button class="cancel-button" (click)="onClose()">{{'Cancel' | translate}}</button>
</div>
</div>

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div class="dialog-container">
<h2 class="dialog-container" >{{ data.name }} Extra information</h2>
<h2 class="dialog-container" >{{ data.name }} {{'Extra information' | translate}}</h2>
<p>{{"Please include any information required about farming this crop."}}</p>
<input class="inputField" [(ngModel)]="editedExtraInformation" placeholder="Edit extra information" />
<div mat-dialog-actions>
<button mat-button (click)="onSave()">Save</button>
<button mat-button (click)="onClose()">Close</button>
<button mat-button (click)="onSave()">{{'Save'|translate}}</button>
<button mat-button (click)="onClose()">{{'Close'|translate}}</button>
</div>
</div>
Loading

0 comments on commit 47e1ded

Please sign in to comment.