Skip to content

Commit

Permalink
Merge branch 'rc/12.0.0' into feature/11-3-0-into-12-0-0
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasMinkeRitense authored May 21, 2024
2 parents e77ebe6 + ca25cc3 commit 78b005e
Show file tree
Hide file tree
Showing 20 changed files with 252 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
</ng-template>

<ng-template #rowDisabled let-data="data">
<div *ngIf="data.locked" class="disabled">
<div *ngIf="data.locked" class="locked">
<span
class="float-right badge badge-pill badge-secondary bg-grey"
ngbTooltip="{{ lockedTooltipTranslationKey | translate }}"
Expand Down Expand Up @@ -153,19 +153,25 @@
</ng-template>

<ng-template #tagTemplate let-data="data">
<ng-container *ngIf="!data.tags">-</ng-container>

<div *ngIf="data.tags" class="tag-template">
<cds-tag *ngIf="!!data.tags[0].content" class="cds-tag--no-margin" [type]="data.tags[0].type">
{{ data.tags[0].content }}
</cds-tag>

<cds-tag
*ngIf="data.tags.length > 1"
class="cds-tag--no-margin valtimo-carbon-list__expand-tag"
type="high-contrast"
(click)="onTagClick($event, data.tags)"
>
{{ data.tags.length - 1 }} <svg cdsIcon="add" size="16"></svg>
</cds-tag>
@if (data.tags.length === 0) {
-
} @else {
<cds-tag *ngIf="!!data.tags[0].content" class="cds-tag--no-margin" [type]="data.tags[0].type">
{{ data.tags[0].content }}
</cds-tag>

<cds-tag
*ngIf="data.tags.length > 1"
class="cds-tag--no-margin valtimo-carbon-list__expand-tag"
type="high-contrast"
(click)="onTagClick($event, data.tags)"
>
{{ data.tags.length - 1 }} <svg cdsIcon="add" size="16"></svg>
</cds-tag>
}
</div>
</ng-template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ td:first-child {
padding-left: 25px;
}

::ng-deep tr:has(> td .locked) {
cursor: not-allowed;

td {
color: var(--cds-text-on-color-disabled);
}
}

.valtimo-carbon-list {
::ng-deep &__header--hidden thead {
display: none;
Expand Down Expand Up @@ -94,7 +102,3 @@ td:first-child {
}
}
}

.disabled {
cursor: not-allowed;
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export class CarbonListComponent implements OnInit, AfterViewInit, OnDestroy {
});
case ViewType.TAGS:
return new TableItem({
data: {tags: item.tags},
data: {tags: item?.tags ?? []},
template: this.tagTemplate,
});
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,25 @@ import {
Formio,
FormioComponent as FormIoSourceComponent,
FormioOptions,
FormioRefreshValue,
FormioSubmission,
FormioUtils,
} from '@formio/angular';
import {FormioRefreshValue} from '@formio/angular/formio.common';
import {jwtDecode} from 'jwt-decode';
import {NGXLogger} from 'ngx-logger';
import {BehaviorSubject, combineLatest, Observable, Subject, Subscription, timer} from 'rxjs';
import {distinctUntilChanged, map, switchMap, take, tap} from 'rxjs/operators';
import {FormIoStateService} from './services/form-io-state.service';
import {ActivatedRoute} from '@angular/router';
import {TranslateService} from '@ngx-translate/core';
import {FormIoLocalStorageService} from './services/form-io-local-storage.service';
import {deepmerge} from 'deepmerge-ts';
import {ConfigService, ValtimoConfig} from '@valtimo/config';

@Component({
selector: 'valtimo-form-io',
templateUrl: './form-io.component.html',
styleUrls: ['./form-io.component.css'],
providers: [FormIoLocalStorageService],
})
export class FormioComponent implements OnInit, OnChanges, OnDestroy {
@Input() set options(optionsValue: ValtimoFormioOptions) {
Expand All @@ -73,7 +74,7 @@ export class FormioComponent implements OnInit, OnChanges, OnDestroy {

@HostListener('window:beforeunload', ['$event'])
private handleBeforeUnload() {
this.clearTokenFromLocalStorage();
this.localStorageService.clearTokenFromLocalStorage();
}

public refreshForm = new EventEmitter<FormioRefreshValue>();
Expand All @@ -83,7 +84,6 @@ export class FormioComponent implements OnInit, OnChanges, OnDestroy {
public readonly options$ = new BehaviorSubject<ValtimoFormioOptions>(undefined);
public readonly readOnly$ = new BehaviorSubject<boolean>(false);
public readonly errors$ = new BehaviorSubject<Array<string>>([]);
public readonly tokenSetInLocalStorage$ = new BehaviorSubject<boolean>(false);

public readonly currentLanguage$ = this.translateService.stream('key').pipe(
map(() => this.translateService.currentLang),
Expand Down Expand Up @@ -115,19 +115,20 @@ export class FormioComponent implements OnInit, OnChanges, OnDestroy {
tap(options => this.logger.debug('Form.IO options used', options))
);

public readonly tokenSetInLocalStorage$ = this.localStorageService.tokenSetInLocalStorage$;

private _tokenRefreshTimerSubscription!: Subscription;
private _formRefreshSubscription!: Subscription;
private readonly _subscriptions = new Subscription();
private readonly _tokenTimerSubscription = new Subscription();

private readonly _FORMIO_TOKEN_LOCAL_STORAGE_KEY = 'formioToken';

constructor(
private readonly userProviderService: UserProviderService,
private readonly logger: NGXLogger,
private readonly stateService: FormIoStateService,
private readonly route: ActivatedRoute,
private readonly translateService: TranslateService,
private readonly localStorageService: FormIoLocalStorageService,
private readonly modalService: ValtimoModalService,
private readonly configService: ConfigService
) {
Expand Down Expand Up @@ -157,7 +158,7 @@ export class FormioComponent implements OnInit, OnChanges, OnDestroy {
this.unsubscribeFormRefresh();
this._tokenRefreshTimerSubscription?.unsubscribe();
this._subscriptions.unsubscribe();
this.clearTokenFromLocalStorage();
this.localStorageService.clearTokenFromLocalStorage();
}

public showErrors(errors: string[]): void {
Expand Down Expand Up @@ -218,9 +219,8 @@ export class FormioComponent implements OnInit, OnChanges, OnDestroy {
private setToken(token: string): void {
Formio.setUser(jwtDecode(token));
Formio.setToken(token);
localStorage.setItem(this._FORMIO_TOKEN_LOCAL_STORAGE_KEY, token);
this.setTimerForTokenRefresh(token);
this.tokenSetInLocalStorage$.next(true);
this.localStorageService.setTokenInLocalStorage(token);

this.logger.debug('New token set for form.io.');
}
Expand Down Expand Up @@ -277,10 +277,6 @@ export class FormioComponent implements OnInit, OnChanges, OnDestroy {
);
}

private clearTokenFromLocalStorage(): void {
localStorage.removeItem(this._FORMIO_TOKEN_LOCAL_STORAGE_KEY);
}

private setOverrideOptions(config: ValtimoConfig): void {
if (!config.formioOptions) return;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2015-2024 Ritense BV, the Netherlands.
*
* Licensed under EUPL, Version 1.2 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {Injectable} from '@angular/core';
import {BehaviorSubject, Observable} from 'rxjs';

@Injectable()
export class FormIoLocalStorageService {
private readonly _FORMIO_TOKEN_LOCAL_STORAGE_KEY = 'formioToken';
private readonly _tokenSetInLocalStorage$ = new BehaviorSubject<boolean>(false);

public get tokenSetInLocalStorage$(): Observable<boolean> {
return this._tokenSetInLocalStorage$.asObservable();
}

public setTokenInLocalStorage(token: string): void {
setTimeout(() => {
localStorage.setItem(this._FORMIO_TOKEN_LOCAL_STORAGE_KEY, token);
this.checkIfTokenExistsInLocalStorage();
});
}

public clearTokenFromLocalStorage(): void {
localStorage.removeItem(this._FORMIO_TOKEN_LOCAL_STORAGE_KEY);
this.checkIfTokenIsRemovedFromLocalStorage();
}

private getTokenFromLocalStorage(): string | null {
return localStorage.getItem(this._FORMIO_TOKEN_LOCAL_STORAGE_KEY);
}

private checkIfTokenExistsInLocalStorage(): void {
const maxChecks = 100;
let checks = 0;

if (this.getTokenFromLocalStorage()) {
this._tokenSetInLocalStorage$.next(true);
} else if (checks <= maxChecks) {
checks++;
this.checkIfTokenExistsInLocalStorage();
}
}

private checkIfTokenIsRemovedFromLocalStorage(): void {
const maxChecks = 100;
let checks = 0;

if (this.getTokenFromLocalStorage() && checks <= maxChecks) {
checks++;
this.checkIfTokenIsRemovedFromLocalStorage();
} else {
this._tokenSetInLocalStorage$.next(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@
<cds-list-row>
<cds-list-column>
<cds-dropdown
[id]="'language-dropdown'"
[appendInline]="true"
[dropUp]="false"
(click)="$event.stopPropagation()"
(selected)="updateUserLanguage($event)"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
class="overflow-button"
>
<cds-overflow-menu-option
[id]="'exportDocumentDefinition'"
[disabled]="obs.exporting || obs.loadingVersion"
(selected)="export()"
>{{
Expand All @@ -65,6 +66,7 @@

<cds-overflow-menu-option
*ngIf="obs.selectedDocumentDefinition && !obs.selectedDocumentDefinition.readOnly"
[id]="'removeDocumentDefinition'"
[disabled]="obs.exporting || obs.loadingVersion"
(selected)="openDossierRemoveModal()"
>{{ 'Remove document definition' | translate }}</cds-overflow-menu-option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ <h3 cdsModalHeaderHeading>
{{ 'dossierManagement.statuses.columns.color' | translate }}

<cds-dropdown
[id]="'status-color-dropdown'"
[appendInline]="false"
[placeholder]="'dossierManagement.statuses.colorPlaceholder' | translate"
(selected)="colorDropdownChange($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import {
import {CARBON_CONSTANTS} from '@valtimo/components';
import {
AbstractControl,
AsyncValidatorFn,
FormBuilder,
ValidationErrors,
ValidatorFn,
Validators,
} from '@angular/forms';
import {
Expand All @@ -61,7 +61,7 @@ import {TranslateService} from '@ngx-translate/core';
})
export class DossierManagementStatusModalComponent implements OnInit, OnDestroy {
@Input() public set type(value: StatusModalType) {
this._type.next(value);
this._type$.next(value);

if (value === 'closed') {
setTimeout(() => {
Expand All @@ -81,18 +81,16 @@ export class DossierManagementStatusModalComponent implements OnInit, OnDestroy

@Output() public closeModalEvent = new EventEmitter<StatusModalCloseEvent>();

private readonly _type = new BehaviorSubject<StatusModalType>(undefined);
private readonly _type$ = new BehaviorSubject<StatusModalType>(undefined);
private readonly _typeAnimationDelay$ = new BehaviorSubject<StatusModalType>(undefined);
private readonly _prefillStatus = new BehaviorSubject<InternalCaseStatus>(undefined);

public readonly isClosed$ = this._type.pipe(map(type => type === 'closed'));

public readonly statusFormGroup = this.fb.group({
title: this.fb.control('', Validators.required),
key: this.fb.control('', [
Validators.required,
Validators.minLength(3),
this.uniqueKeyValidator(),
this.uniqueKeyValidator,
]),
visibleInCaseListByDefault: this.fb.control(true, Validators.required),
color: this.fb.control('', Validators.required),
Expand All @@ -112,6 +110,8 @@ export class DossierManagementStatusModalComponent implements OnInit, OnDestroy
})
);

public readonly isClosed$ = this._type$.pipe(map(type => type === 'closed'));

public readonly disabled$ = new BehaviorSubject<boolean>(false);

private readonly COLORS: InternalCaseStatusColor[] = [
Expand Down Expand Up @@ -345,11 +345,15 @@ export class DossierManagementStatusModalComponent implements OnInit, OnDestroy
this.statusFormGroup.patchValue({key: ''});
}

private uniqueKeyValidator(): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null =>
this.usedKeys?.every((key: string) => key !== control.value)
? null
: {uniqueKey: {value: control.value}};
private uniqueKeyValidator(): AsyncValidatorFn {
return (control: AbstractControl): Observable<ValidationErrors | null> =>
combineLatest([this.isEdit$, control.valueChanges]).pipe(
map(([isEdit, keyValue]) =>
this.usedKeys?.every((key: string) => key !== keyValue) || isEdit
? null
: {uniqueKey: {value: control.value}}
)
);
}

private disable(): void {
Expand Down
Loading

0 comments on commit 78b005e

Please sign in to comment.