Auto-seleccionar o periodo mais recente (fixes #11)
This commit is contained in:
parent
13618db55a
commit
213aac98e7
5 changed files with 42 additions and 26 deletions
|
@ -91,12 +91,12 @@ export class DashboardComponentAccordionTable implements OnInit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Listen to changes in PeriodSelector
|
// Get the currently selected ORGANIZATION AND listen to changes in PeriodSelector
|
||||||
this.subscriptionPeriod = this
|
this.subscriptionPeriod = this
|
||||||
.envService
|
.envService
|
||||||
.selectedPeriod
|
.selectedPeriod
|
||||||
.pipe( skip(1)) // Ignore the current value. Just want to react to changes
|
/* .pipe( skip(1)) // Ignore's the current value. If you want to react ONLY to changes */
|
||||||
.subscribe(period => {
|
.subscribe(period => {
|
||||||
if(period){
|
if(period){
|
||||||
// Calculate the latest periodVersionId
|
// Calculate the latest periodVersionId
|
||||||
|
@ -105,9 +105,10 @@ export class DashboardComponentAccordionTable implements OnInit {
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (version: HttpResponse<IPeriodVersion>) => {
|
next: (version: HttpResponse<IPeriodVersion>) => {
|
||||||
if (version.body) {
|
if (version.body) {
|
||||||
const periodVersion = version.body;
|
this.periodVersion = version.body;
|
||||||
this.periodVersionId = periodVersion.id;
|
this.periodVersionId = this.periodVersion.id;
|
||||||
} else {
|
} else {
|
||||||
|
this.periodVersion = null;
|
||||||
this.periodVersionId = null;
|
this.periodVersionId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,14 @@ import { DashboardPreviewComponent } from './preview/dashboard-preview.component
|
||||||
// import DashboardResolve from './route/dashboard-routing-resolve.service';
|
// import DashboardResolve from './route/dashboard-routing-resolve.service';
|
||||||
|
|
||||||
const dashboardRoute: Routes = [
|
const dashboardRoute: Routes = [
|
||||||
|
{
|
||||||
|
path: ':view',
|
||||||
|
component: DashboardPreviewComponent,
|
||||||
|
canActivate: [UserRouteAccessService],
|
||||||
|
data: {
|
||||||
|
authorities: ['ROLE_ADMIN', 'ROLE_MANAGER', 'ROLE_COORDINATOR', 'ROLE_USER'],
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: ':view/:period',
|
path: ':view/:period',
|
||||||
component: DashboardPreviewComponent,
|
component: DashboardPreviewComponent,
|
||||||
|
|
|
@ -23,10 +23,9 @@ export class DashboardPreviewComponent implements OnInit, AfterViewInit {
|
||||||
@ViewChild('dashboardContainer', { read: ViewContainerRef }) container!: ViewContainerRef;
|
@ViewChild('dashboardContainer', { read: ViewContainerRef }) container!: ViewContainerRef;
|
||||||
|
|
||||||
dashboardComponents?: IDashboardComponent[];
|
dashboardComponents?: IDashboardComponent[];
|
||||||
periodsSharedCollection: IPeriod[] = [];
|
|
||||||
|
|
||||||
dashboardView: string | null = null;
|
dashboardView: string | null = null;
|
||||||
periodId: number = 0;
|
periodId: number | null = null;
|
||||||
periodVersionId: number | null = null;
|
periodVersionId: number | null = null;
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
|
|
||||||
|
@ -54,8 +53,11 @@ export class DashboardPreviewComponent implements OnInit, AfterViewInit {
|
||||||
this.dashboardView = params.get('view') ?? null;
|
this.dashboardView = params.get('view') ?? null;
|
||||||
|
|
||||||
// used the operator (+) that auto-casts a string to a number
|
// used the operator (+) that auto-casts a string to a number
|
||||||
this.periodId = +(params.get('period') ?? 0);
|
// this.periodId = +(params.get('period') ?? 0);
|
||||||
|
if (params.get('period') != null) {
|
||||||
|
this.periodId = +(params.get('period')!);
|
||||||
|
}
|
||||||
|
|
||||||
// periodVersion might not be defined. In this case, it will calculate the most recent version
|
// periodVersion might not be defined. In this case, it will calculate the most recent version
|
||||||
if (params.get('period_version') != null) {
|
if (params.get('period_version') != null) {
|
||||||
this.periodVersionId = +(params.get('period_version')!);
|
this.periodVersionId = +(params.get('period_version')!);
|
||||||
|
@ -68,8 +70,12 @@ export class DashboardPreviewComponent implements OnInit, AfterViewInit {
|
||||||
this.build();
|
this.build();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get the latest PeriodVersion for the requested Period
|
if (this.periodId == null) {
|
||||||
if (this.periodVersionId == null) {
|
// Get the latest Period + PeriodVersion
|
||||||
|
// Do nothing. The period selector will auto-select the moust recent period
|
||||||
|
|
||||||
|
} else if (this.periodId && this.periodVersionId == null) {
|
||||||
|
// Get the latest PeriodVersion for the requested Period
|
||||||
this.periodService
|
this.periodService
|
||||||
.lastVersion(this.periodId)
|
.lastVersion(this.periodId)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
|
@ -89,8 +95,6 @@ export class DashboardPreviewComponent implements OnInit, AfterViewInit {
|
||||||
//Fire Loading of the dashboard
|
//Fire Loading of the dashboard
|
||||||
this.build();
|
this.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loadRelationshipsOptions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onSearch(): void {
|
onSearch(): void {
|
||||||
|
@ -102,11 +106,14 @@ export class DashboardPreviewComponent implements OnInit, AfterViewInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
build(): void {
|
build(): void {
|
||||||
if (this.periodVersionId == null) {
|
// ALWAYS load, even if no period is selected.
|
||||||
// Can't load dashboard without a version
|
/*
|
||||||
|
if (this.periodId == null || this.periodVersionId == null) {
|
||||||
|
// Can't load dashboard without a period || periodVersion
|
||||||
this.dashboardComponents = []; // Clear components
|
this.dashboardComponents = []; // Clear components
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Load a list of dashboarComponent's to render
|
// Load a list of dashboarComponent's to render
|
||||||
this.loadDashboards().subscribe({
|
this.loadDashboards().subscribe({
|
||||||
|
@ -141,15 +148,6 @@ export class DashboardPreviewComponent implements OnInit, AfterViewInit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected loadRelationshipsOptions(): void {
|
|
||||||
this.periodService
|
|
||||||
.query()
|
|
||||||
.pipe(map((res: HttpResponse<IPeriod[]>) => res.body ?? []))
|
|
||||||
.subscribe((periods: IPeriod[]) => {
|
|
||||||
this.periodsSharedCollection = periods;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected setPageTitles(view: string | null): void {
|
protected setPageTitles(view: string | null): void {
|
||||||
this.pageTitle = '';
|
this.pageTitle = '';
|
||||||
this.pageSubTitle = '';
|
this.pageSubTitle = '';
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
>
|
>
|
||||||
<a
|
<a
|
||||||
class="nav-link"
|
class="nav-link"
|
||||||
routerLink="/dashboard/EMISSIONS/1500"
|
routerLink="/dashboard/EMISSIONS"
|
||||||
routerLinkActive="active"
|
routerLinkActive="active"
|
||||||
[routerLinkActiveOptions]="{ exact: true }"
|
[routerLinkActiveOptions]="{ exact: true }"
|
||||||
(click)="collapseNavbar()"
|
(click)="collapseNavbar()"
|
||||||
|
@ -68,7 +68,7 @@
|
||||||
>
|
>
|
||||||
<a
|
<a
|
||||||
class="nav-link"
|
class="nav-link"
|
||||||
routerLink="/dashboard/INDICATORS/1500"
|
routerLink="/dashboard/INDICATORS"
|
||||||
routerLinkActive="active"
|
routerLinkActive="active"
|
||||||
[routerLinkActiveOptions]="{ exact: true }"
|
[routerLinkActiveOptions]="{ exact: true }"
|
||||||
(click)="collapseNavbar()"
|
(click)="collapseNavbar()"
|
||||||
|
|
|
@ -63,6 +63,7 @@ export class PeriodSelectorComponent implements OnInit {
|
||||||
const queryObject: any = {
|
const queryObject: any = {
|
||||||
eagerload: true,
|
eagerload: true,
|
||||||
sort: this.sortService.buildSortParam(this.sortState()),
|
sort: this.sortService.buildSortParam(this.sortState()),
|
||||||
|
|
||||||
};
|
};
|
||||||
return this.periodService.query(queryObject).pipe(tap(() => (this.isLoading = false)));
|
return this.periodService.query(queryObject).pipe(tap(() => (this.isLoading = false)));
|
||||||
}
|
}
|
||||||
|
@ -71,6 +72,14 @@ export class PeriodSelectorComponent implements OnInit {
|
||||||
const dataFromBody = this.fillComponentAttributesFromResponseBody(response.body);
|
const dataFromBody = this.fillComponentAttributesFromResponseBody(response.body);
|
||||||
this.periods = this.refineData(dataFromBody);
|
this.periods = this.refineData(dataFromBody);
|
||||||
if (this.periods.length >= 1) {
|
if (this.periods.length >= 1) {
|
||||||
|
// Sort the periods
|
||||||
|
this.periods.sort((a, b) => {
|
||||||
|
if (!a.beginDate && !b.beginDate) return 0;
|
||||||
|
if (!a.beginDate) return 1; // null dates go last
|
||||||
|
if (!b.beginDate) return -1;
|
||||||
|
return b.beginDate.valueOf() - a.beginDate.valueOf();
|
||||||
|
});
|
||||||
|
|
||||||
if (this.defaultSelectedPeriodId) {
|
if (this.defaultSelectedPeriodId) {
|
||||||
// Select the provided default Period
|
// Select the provided default Period
|
||||||
this.selectedPeriod = this.periods.find(period => period.id === this.defaultSelectedPeriodId) || undefined;
|
this.selectedPeriod = this.periods.find(period => period.id === this.defaultSelectedPeriodId) || undefined;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue