Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class DashboardComponent
this.route.params.pipe(takeUntil(this.destroy$)).subscribe((params) => {
this.loading = true;
this.id = params.id;
this.dashboardService.currentDashboardId = this.id;
this.apollo
.query<DashboardQueryResponse>({
query: GET_DASHBOARD_BY_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ApplicationService,
ConfirmService,
UnsubscribeComponent,
ContextService,
} from '@oort-front/shared';
import get from 'lodash/get';
import { takeUntil, map } from 'rxjs/operators';
Expand Down Expand Up @@ -49,13 +50,15 @@ export class ApplicationComponent
* @param router Angular router
* @param translate Angular translate service
* @param confirmService Shared confirmation service
* @param contextService ContextService
*/
constructor(
private applicationService: ApplicationService,
public route: ActivatedRoute,
private router: Router,
private translate: TranslateService,
private confirmService: ConfirmService
private confirmService: ConfirmService,
private contextService: ContextService
) {
super();
this.largeDevice = window.innerWidth > 1024;
Expand Down Expand Up @@ -270,12 +273,16 @@ export class ApplicationComponent
return dialogRef.closed.pipe(
map((confirm) => {
if (confirm) {
// Clear any context filter history from current application
this.contextService.filterHistory.clear();
return true;
}
return false;
})
);
}
// Clear any context filter history from current application
this.contextService.filterHistory.clear();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export class DashboardComponent
.then(({ data }) => {
if (data.dashboard) {
this.id = data.dashboard.id || id;
this.dashboardService.currentDashboardId = this.id;
this.dashboard = data.dashboard;
this.gridOptions = {
...omit(this.gridOptions, ['gridType', 'minimumHeight']), // Prevent issue when gridType or minimumHeight was not set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,7 @@ export class DashboardFilterComponent
const currentSurveyQuestions = this.survey.getAllQuestions();
const nextFilterValue: any = surveyData;
// Don't merge current context filter values to the filter if survey has init and it's used in web component
if (
!(this.surveyInit && this.contextService.shadowDomService.isShadowRoot)
) {
if (!this.surveyInit) {
const currentFilterValue = this.contextService.filter.value;
const filterKeys = Object.keys(currentFilterValue);
filterKeys
Expand Down
44 changes: 25 additions & 19 deletions libs/shared/src/lib/services/context/context.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {
get,
isEqual,
isObject,
forEach,
set,
has,
isArray,
every,
Expand All @@ -38,6 +36,7 @@ import { ApplicationService } from '../application/application.service';
import { ActivatedRoute, Router } from '@angular/router';
import { RecordQueryResponse } from '../../models/record.model';
import { GET_RECORD_BY_ID } from './graphql/queries';
import { DashboardService } from '../dashboard/dashboard.service';

/**
* Dashboard context service
Expand All @@ -55,7 +54,7 @@ export class ContextService {
dashboardId: string;
} | null>(null);
/** To keep the history of previous dashboard filter values */
public filterValues = new BehaviorSubject<any>(null);
public filterHistory = new Map();
/** Is filter opened */
public filterOpened = new BehaviorSubject<boolean>(false);
/** Should skip filter, used by the web widgets app, so when a page is redrawn, emit a value */
Expand Down Expand Up @@ -112,11 +111,6 @@ export class ContextService {
return this.filterPosition.asObservable();
}

/** @returns filterValues value as observable */
get filterValues$() {
return this.filterValues.asObservable();
}

/** @returns filterOpened value as observable */
get filterOpened$() {
return this.filterOpened.asObservable();
Expand Down Expand Up @@ -146,6 +140,7 @@ export class ContextService {
* @param applicationService Shared application service
* @param router Angular router
* @param {ShadowDomService} shadowDomService Shadow dom service containing the current DOM host
* @param dashboardService Shared dashboard service
*/
constructor(
private dialog: Dialog,
Expand All @@ -155,7 +150,8 @@ export class ContextService {
private formBuilderService: FormBuilderService,
private applicationService: ApplicationService,
private router: Router,
public shadowDomService: ShadowDomService
public shadowDomService: ShadowDomService,
private dashboardService: DashboardService
) {
this.filterPosition$.subscribe(
(value: { position: FilterPosition; dashboardId: string } | null) => {
Expand Down Expand Up @@ -426,20 +422,30 @@ export class ContextService {
*/
public initSurvey(structure: any): SurveyModel {
const survey = this.formBuilderService.createSurvey(structure);
// set each question value manually otherwise the defaultValueExpression is not loaded

if (!this.shadowDomService.isShadowRoot) {
forEach(this.filterValues.getValue(), (value, key) => {
if (survey.getQuestionByName(key)) {
survey.getQuestionByName(key).value = value;
}
});
if (this.filterHistory.has(this.dashboardService.currentDashboardId)) {
const previousSurveyValue = this.filterHistory.get(
this.dashboardService.currentDashboardId
);
survey.data = previousSurveyValue;
} else {
this.filterHistory.set(this.dashboardService.currentDashboardId, {
...survey.data,
});
}
}

// prevent the default value from being applied when a question has been intentionally cleared
const handleValueChanged = (sender: any, options: any) => {
const history = this.filterValues.getValue() ?? {};
set(history, options.name, options.value);
this.filterValues.next(history);
if (this.filterHistory.has(this.dashboardService.currentDashboardId)) {
const previousSurveyValue = this.filterHistory.get(
this.dashboardService.currentDashboardId
);
this.filterHistory.set(this.dashboardService.currentDashboardId, {
...previousSurveyValue,
[options.name]: options.value,
});
}
};

survey.onValueChanged.add(handleValueChanged);
Expand Down
2 changes: 2 additions & 0 deletions libs/shared/src/lib/services/dashboard/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export class DashboardService {
public widgets: BehaviorSubject<any[]> = new BehaviorSubject<any[]>([]);
/** Observable of current loaded dashboard widgets */
public widgets$ = this.widgets.asObservable();
/** Current dashboard id in the view */
public currentDashboardId = '';

/** @returns To listen when dashboard widgets that can be hidden refreshes its contents */
get widgetContentRefreshed$(): Observable<any> {
Expand Down