Skip to content

Commit

Permalink
Merge pull request #123 from e-picsa/feat/crop-prob-tool-integration
Browse files Browse the repository at this point in the history
feat: integrate crop probability tool into main app
  • Loading branch information
chrismclarke authored Apr 15, 2023
2 parents 016ef66 + 2a17373 commit 30df8c5
Show file tree
Hide file tree
Showing 20 changed files with 230 additions and 32 deletions.
4 changes: 2 additions & 2 deletions apps/picsa-apps/extension-app-native/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "io.picsa.extension"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 3017000
versionName "3.17.0"
versionCode 3018000
versionName "3.18.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
Expand Down
9 changes: 9 additions & 0 deletions apps/picsa-apps/extension-app/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { BudgetToolModule } from '@picsa/budget/src/app/app.module-embedded';
import { ClimateToolModule } from '@picsa/climate/src/app/app.module-embedded';
import { CropProbabilityToolModule } from '@picsa/crop-probability/src/app/app.module-embedded';
import { MonitoringToolModule } from '@picsa/monitoring/src/app/app.module-embedded';
import { OptionsToolModule } from '@picsa/option/src/app/app.module-embedded';
import { ResourcesToolModule } from '@picsa/resources/src/app/app.module-embedded';
Expand All @@ -24,6 +25,13 @@ const routes: Routes = [
(mod) => mod.ClimateToolModule
),
},
{
path: 'crop-probability',
loadChildren: () =>
import('@picsa/crop-probability/src/app/app.module-embedded').then(
(mod) => mod.CropProbabilityToolModule
),
},
{
path: 'monitoring',
loadChildren: () =>
Expand Down Expand Up @@ -81,6 +89,7 @@ const routes: Routes = [
imports: [
RouterModule.forRoot(routes),
ClimateToolModule.forRoot({ urlPrefix: 'climate' }),
CropProbabilityToolModule.forRoot({ urlPrefix: 'crop-probability' }),
BudgetToolModule.forRoot({ urlPrefix: 'budget' }),
MonitoringToolModule.forRoot({ urlPrefix: 'monitoring' }),
OptionsToolModule.forRoot({ urlPrefix: 'option' }),
Expand Down
2 changes: 1 addition & 1 deletion apps/picsa-tools/crop-probability-tool/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
"maximumError": "2mb"
},
{
"type": "anyComponentStyle",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
import { NgModule } from '@angular/core';

export const ROUTES_COMMON: Routes = [
{
path: '',
loadChildren: () =>
import('./pages/home/home.module').then((m) => m.HomeModule),
title: 'Crop Probability',
},
];
/** Routes only registered in standalone mode */
const ROUTES_STANDALONE: Routes = [{ path: '**', redirectTo: '' }];

/*******************************************************************
* Standalone Version
******************************************************************/
@NgModule({
imports: [
RouterModule.forRoot([...ROUTES_COMMON, ...ROUTES_STANDALONE], {
preloadingStrategy: PreloadAllModules,
}),
],
exports: [RouterModule],
})
export class AppRoutingModule {}
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<picsa-crop-probability-table></picsa-crop-probability-table>
<div class="page">
<picsa-header></picsa-header>
<router-outlet></router-outlet>
</div>
13 changes: 11 additions & 2 deletions apps/picsa-tools/crop-probability-tool/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { Component } from '@angular/core';

@Component({
selector: 'picsa-root',
// eslint-disable-next-line @angular-eslint/component-selector
selector: 'picsa-crop-probability-tool',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
title = 'picsa-tools-crop-probability-tool';
title = 'picsa-crop-probability';
}

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: 'picsa-crop-probability-tool',
template: '',
})
// eslint-disable-next-line @angular-eslint/component-class-suffix
export class AppComponentEmbedded extends AppComponent {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { ModuleWithProviders, NgModule } from '@angular/core';
import { Router, RouterModule } from '@angular/router';
import { PicsaTranslateService } from '@picsa/shared/modules';

import { registerEmbeddedRoutes } from '@picsa/utils';

import { APP_COMMON_IMPORTS } from './app.module';
import { AppComponentEmbedded } from './app.component';
import { ROUTES_COMMON } from './app-routing.module';

export class EmbeddedConfig {
/** Path app routed through, e.g. 'budget' */
urlPrefix: string;
}

/*******************************************************************
* Routes
******************************************************************/
@NgModule({
imports: [RouterModule.forChild([])],
})
export class EmbeddedRoutingModule {
constructor(router: Router, embeddedConfig: EmbeddedConfig) {
registerEmbeddedRoutes(ROUTES_COMMON, router, embeddedConfig.urlPrefix);
}
}

/*******************************************************************
* Module
******************************************************************/
@NgModule({
declarations: [AppComponentEmbedded],
imports: [...APP_COMMON_IMPORTS, EmbeddedRoutingModule],
bootstrap: [AppComponentEmbedded],
})
export class BaseModule {
// ensure translate has been initiated
constructor(public translate: PicsaTranslateService) {}
}

/** Use to import directly into another app via lazy-loading */
@NgModule()
export class CropProbabilityToolModule {
static forRoot(config: EmbeddedConfig): ModuleWithProviders<BaseModule> {
return {
ngModule: BaseModule,
providers: [
PicsaTranslateService,
{ provide: EmbeddedConfig, useValue: config },
],
};
}
}
61 changes: 42 additions & 19 deletions apps/picsa-tools/crop-probability-tool/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
import { NgModule } from '@angular/core';
import {
BrowserAnimationsModule,
NoopAnimationsModule,
} from '@angular/platform-browser/animations';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';

import {
PicsaDbModule,
PicsaTranslateModule,
PicsaTranslateService,
} from '@picsa/shared/modules';
import { PicsaCommonComponentsModule } from '@picsa/components';

import { AppComponent } from './app.component';
import { RouterModule } from '@angular/router';
import { appRoutes } from './app.routes';
import { CropProbabilityTableComponent } from './components/crop-probability-table/crop-probability-table.component';
import { AppRoutingModule } from './app-routing.module';
import { CropProbabilityMaterialModule } from './components/material.module';
import { CropProbabilityTableHeaderComponent } from './components/crop-probability-table-header/crop-probability-table-header.component';

/** Core imports only required when running standalone */
const StandaloneImports = [
AppRoutingModule,
BrowserModule,
BrowserAnimationsModule,
NoopAnimationsModule,
PicsaTranslateModule.forRoot(),
];

/** Common imports used in both standalone and embedded formats */
export const APP_COMMON_IMPORTS = [
HttpClientModule,
CropProbabilityMaterialModule,
PicsaTranslateModule,
PicsaDbModule.forRoot(),
PicsaCommonComponentsModule,
];

/*******************************************************************
* Standalone Version
******************************************************************/
@NgModule({
declarations: [
AppComponent,
CropProbabilityTableComponent,
CropProbabilityTableHeaderComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
RouterModule.forRoot(appRoutes, { initialNavigation: 'enabledBlocking' }),
CropProbabilityMaterialModule,
],
providers: [],
declarations: [AppComponent],
imports: [...StandaloneImports, ...APP_COMMON_IMPORTS],
bootstrap: [AppComponent],
schemas: [],
})
export class AppModule {}
export class AppModule {
// ensure translate service initialised
constructor(public translate: PicsaTranslateService) {}
}
3 changes: 0 additions & 3 deletions apps/picsa-tools/crop-probability-tool/src/app/app.routes.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { NgModule } from '@angular/core';

import { CropProbabilityTableComponent } from './crop-probability-table/crop-probability-table.component';
import { CropProbabilityMaterialModule } from './material.module';
import { CropProbabilityTableHeaderComponent } from './crop-probability-table-header/crop-probability-table-header.component';
import { FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';

const components = [
CropProbabilityTableComponent,
CropProbabilityTableHeaderComponent,
];

@NgModule({
imports: [CommonModule, FormsModule, CropProbabilityMaterialModule],
exports: components,
declarations: components,
providers: [],
})
export class CropProbabilityToolComponentsModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<picsa-crop-probability-table></picsa-crop-probability-table>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { HomeComponent } from './home.component';

describe('HomeComponent', () => {
let component: HomeComponent;
let fixture: ComponentFixture<HomeComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [HomeComponent],
}).compileComponents();

fixture = TestBed.createComponent(HomeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Component } from '@angular/core';

@Component({
selector: 'picsa-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss'],
})
export class HomeComponent {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { NgModule } from '@angular/core';
import { Route, RouterModule } from '@angular/router';

import { CropProbabilityToolComponentsModule } from '../../components/components.module';
import { HomeComponent } from './home.component';
import { CommonModule } from '@angular/common';
import { PicsaTranslateModule } from '@picsa/shared/modules';

const routes: Route[] = [
{
path: '',
component: HomeComponent,
},
];

@NgModule({
imports: [
CommonModule,
CropProbabilityToolComponentsModule,
RouterModule.forChild(routes),
PicsaTranslateModule,
],
exports: [],
declarations: [HomeComponent],
providers: [],
})
export class HomeModule {}
2 changes: 1 addition & 1 deletion apps/picsa-tools/crop-probability-tool/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
<picsa-root></picsa-root>
<picsa-crop-probability-tool></picsa-crop-probability-tool>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class BaseModule {
@NgModule()
export class ResourcesToolModule {
static forRoot(config: EmbeddedConfig): ModuleWithProviders<BaseModule> {
console.log('resources module forRoot', config);
return {
ngModule: BaseModule,
providers: [
Expand Down
2 changes: 1 addition & 1 deletion libs/environments/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import packageJson from '../../../package.json';

export const APP_VERSION = {
number: packageJson.version,
date: '2023-04-12',
date: '2023-04-14',
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "picsa-apps",
"version": "3.17.0",
"version": "3.18.0",
"license": "See LICENSE",
"scripts": {
"ng": "nx",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@picsa/climate/*": ["apps/picsa-tools/climate-tool/*"],
"@picsa/components": ["libs/components/src/index.ts"],
"@picsa/configuration": ["libs/configuration/src/index.ts"],
"@picsa/crop-probability/*": ["apps/picsa-tools/crop-probability-tool/*"],
"@picsa/dashboard/*": ["apps/sites/dashboard/*"],
"@picsa/environments": ["libs/environments/src/index.ts"],
"@picsa/extension/*": ["apps/native/extension-toolkit/*"],
Expand Down

0 comments on commit 30df8c5

Please sign in to comment.