Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Select Git revision
  • 3d4b00bbcff1196e43e6e1f7383c28e924f86591
  • development default
  • release/5.1.x
  • feature/EDELIVERY-15382-rest-api-jwt-authentication-for-dynamic-discovery-client
  • feature/EDELIVERY-13760-translate-server-side-error-messages
  • bugfix/EDELIVERY-14172-domismp-accepts-requests-with-wrong-domain-header-value
  • EDELIVERY-15372-upgrade-libraries-and-plugins-and-update-httpclient-to-httpclient5
  • EDELIVERY-15377-migrate-to-angular-20
  • bugfix/EDELIVERY-14196-select-domain-select-resource-dropdown-should-be-order-alphabetically
  • feature/EDELIVERY-12753-sml-integration-migration-to-different-smp
  • feature/EDELIVERY-13757-extend-session-dialog-should-have-an-active-counter
  • EDELIVERY-15144-sql-update
  • bugfix/EDELIVERY-14326-ui-edit-resource-filters
  • feature/EDELIVERY-15144-domismp-system-notification-generalize-time-expiration-alerts
  • bugfix/EDELIVERY-15102-alert-is-not-appearing-when-adding-duplicated-certificate
  • bugfix/EDELIVERY-15203-small-left-grid-shows-no-data-found-for-1-2-seconds-before-loading-the-data
  • EDELIVERY-15219-search-filter-with-understore-char-does-not-work
  • bugfix/EDELIVERY-15226-certificates-error-when-trying-to-delete-certificates
  • bugfix/EDELIVERY-15224-error-when-trying-to-update-info-from-profile-page
  • bugfix/EDELIVERY-15225-emails-are-not-sent-in-domismp
  • feature/EDELIVERY-12746-external-secret-sharing-services-as-vaults
  • 5.1.1
  • 5.1
  • 5.1-TEST
  • 5.1-RC1
  • 5.0.1
  • 5.0
  • 5.0-RC1
  • 4.2
  • 4.2-RC1
  • 4.1.2
  • 4.1.1
  • 4.1.0
  • 4.1.0-RC1
  • 4.0.0
  • 4.0.0-RC1
  • 3.0.2
  • 3.0.1
  • 3.0.0
39 results

resource-document-panel.component.ts

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    resource-document-panel.component.ts 9.80 KiB
    import {AfterViewInit, Component, Input, ViewChild, ViewEncapsulation,} from '@angular/core';
    import {MatDialog, MatDialogRef} from "@angular/material/dialog";
    import {BeforeLeaveGuard} from "../../../window/sidenav/navigation-on-leave-guard";
    import {GroupRo} from "../../../common/model/group-ro.model";
    import {ResourceRo} from "../../../common/model/resource-ro.model";
    import {AlertMessageService} from "../../../common/alert-message/alert-message.service";
    import {DomainRo} from "../../../common/model/domain-ro.model";
    import {ResourceDefinitionRo} from "../../../system-settings/admin-extension/resource-definition-ro.model";
    import {EditResourceService} from "../edit-resource.service";
    import {FormBuilder, FormControl, FormGroup} from "@angular/forms";
    import {CodemirrorComponent} from "@ctrl/ngx-codemirror";
    import {DocumentRo} from "../../../common/model/document-ro.model";
    import {NavigationService} from "../../../window/sidenav/navigation-model.service";
    import {DocumentWizardDialogComponent} from "../document-wizard-dialog/document-wizard-dialog.component";
    import {ConfirmationDialogComponent} from "../../../common/dialogs/confirmation-dialog/confirmation-dialog.component";
    
    @Component({
      moduleId: module.id,
      templateUrl: './resource-document-panel.component.html',
      styleUrls: ['./resource-document-panel.component.scss'],
      encapsulation: ViewEncapsulation.None,
    })
    export class ResourceDocumentPanelComponent implements AfterViewInit, BeforeLeaveGuard {
      title: string = "Resources";
      private _resource: ResourceRo;
    
      _document: DocumentRo;
      @Input() private group: GroupRo;
      @Input() domain: DomainRo;
      @Input() domainResourceDefs: ResourceDefinitionRo[];
    
      @ViewChild("codemirror") codemirror: CodemirrorComponent;
    // code mirror configuration
      codemirrorOptions = {
        lineNumbers: true,
        lineWrapping: true,
        viewportMargin: Infinity,
        mode: 'xml'
      };
    
      resourceForm: FormGroup;
      documentForm: FormGroup;
    
      constructor(private editResourceService: EditResourceService,
                  private alertService: AlertMessageService,
                  private dialog: MatDialog,
                  private navigationService: NavigationService,
                  private formBuilder: FormBuilder) {
        this.resourceForm = formBuilder.group({
          'identifierValue': new FormControl({value: null}),
          'identifierScheme': new FormControl({value: null}),
          'visibility': new FormControl({value: null}),
          'resourceTypeIdentifier': new FormControl({value: null}),
        });
        this.documentForm = formBuilder.group({
          'mimeType': new FormControl({value: null}),
          'name': new FormControl({value: null}),
          'currentResourceVersion': new FormControl({value: null}),
          'payloadVersion': new FormControl({value: null}),
          'payload': new FormControl({value: null}),
        });
        this.resource = editResourceService.selectedResource
    
        this.documentForm.controls['payload'].setValue("")
      }
    
      ngAfterViewInit(): void {
        // this.codemirror.codeMirror.setSize('100%', '100%');
      }
    
      get resource(): ResourceRo {
        let resource = {...this._resource};
        resource.identifierScheme = this.resourceForm.get('identifierScheme').value;
        resource.identifierValue = this.resourceForm.get('identifierValue').value;
        resource.resourceTypeIdentifier = this.resourceForm.get('resourceTypeIdentifier').value;
        resource.visibility = this.resourceForm.get('visibility').value;
        return resource;
      }
    
      @Input() set resource(value: ResourceRo) {
        this._resource = value;
        if (!this._resource) {
          this.navigationService.navigateToHome();
          return;
        }
    
        this.resourceForm.enable();
        this.resourceForm.controls['identifierValue'].setValue(value.identifierValue);
        this.resourceForm.controls['identifierScheme'].setValue(value.identifierScheme);
        this.resourceForm.controls['resourceTypeIdentifier'].setValue(value.resourceTypeIdentifier);
        this.resourceForm.controls['visibility'].setValue(value.visibility);
        // control disable enable did not work??
    
        this.resourceForm.controls['identifierValue'].disable();
        this.resourceForm.controls['identifierScheme'].disable();
        this.resourceForm.controls['resourceTypeIdentifier'].disable();
        this.resourceForm.controls['visibility'].disable();
        this.resourceForm.markAsPristine();
        // load current document for the resource
        this.loadDocumentForVersion();
      }
    
      @Input() set document(value: DocumentRo) {
        this._document = value;
        this.documentForm.disable();
        if (!!value) {
          this.codemirror.setOptionIfChanged("mode",value.mimeType);
          this.documentForm.controls['mimeType'].setValue(value.mimeType);
          this.documentForm.controls['name'].setValue(value.name);
          this.documentForm.controls['currentResourceVersion'].setValue(value.currentResourceVersion);
          this.documentForm.controls['payloadVersion'].setValue(value.payloadVersion);
          this.documentForm.controls['payload'].setValue(!value.payload?"":value.payload);
          this.documentForm.controls['payload'].enable();
          // the method documentVersionsExists already uses the current value to check if versions exists
          if (!this.documentVersionsExists) {
            this.documentForm.controls['payloadVersion'].disable();
          } else {
            this.documentForm.controls['payloadVersion'].enable();
          }
        } else {
          this.documentForm.controls['name'].setValue("");
          this.documentForm.controls['payload'].setValue("");
          this.documentForm.controls['currentResourceVersion'].setValue("");
          this.documentForm.controls['payloadVersion'].setValue("");
          this.documentForm.controls['payload'].setValue("");
        }
        this.documentForm.markAsPristine();
      }
    
      get document(): DocumentRo {
        let doc: DocumentRo = {...this._document};
        doc.payload = this.documentForm.controls['payload'].value;
        return doc;
      }
    
      onDocumentResetButtonClicked(): void {
    
        this.dialog.open(ConfirmationDialogComponent, {
          data: {
            title: "Cancel changes",
            description: "Do you want to cancel all changes on the document?"
          }
        }).afterClosed().subscribe(result => {
          if (result) {
            this.resetChanges()
          }
        });
      }
    
      resetChanges(){
    
        let currentVersion = this._document?.payloadVersion;
        if (!currentVersion) {
          this.documentForm.controls['payload'].setValue("");
          this.documentForm.markAsPristine();
        } else {
          this.loadDocumentForVersion(currentVersion);
        }
      }
    
    
      onSaveButtonClicked(): void {
        this.editResourceService.saveDocumentObservable(this._resource, this.document).subscribe((value: DocumentRo) => {
          if (value) {
            this.alertService.success("Document is saved with current version [" + value.currentResourceVersion + "].")
            this.document = value;
          } else {
            this.document = null;
          }
        }, (error: any) => {
          this.alertService.error(error.error?.errorDescription)
        })
      }
    
      onGenerateButtonClicked(): void {
        this.editResourceService.generateDocumentObservable(this._resource).subscribe((value: DocumentRo) => {
          if (value) {
            this.alertService.success("Document is generated.")
            this.documentForm.controls['payload'].setValue(value.payload);
            this.documentForm.controls['payload'].markAsDirty();
          } else {
            this.document = null;
          }
        }, (error: any) => {
          this.alertService.error(error.error?.errorDescription)
        })
      }
    
      onShowDocumentWizardDialog() {
    
        const formRef: MatDialogRef<any> = this.dialog.open(DocumentWizardDialogComponent, {
          data: {
            title: "Service group wizard",
            resource: this._resource,
    
          }
        });
        formRef.afterClosed().subscribe(result => {
          if (result) {
            let val = formRef.componentInstance.getExtensionXML();
            this.documentForm.controls['payload'].setValue(val);
            this.documentForm.controls['payload'].markAsDirty();
          }
        });
      }
    
      loadDocumentForVersion(version: number = null): void {
        this.editResourceService.getDocumentObservable(this._resource, version).subscribe((value: DocumentRo) => {
          if (value) {
            this.document = value;
          } else {
            this.document = null;
          }
        }, (error: any) => {
          this.alertService.error(error.error?.errorDescription)
        });
      }
    
      validateCurrentDocument(): void {
        this.editResourceService.validateDocumentObservable(this._resource, this.document).subscribe((value: DocumentRo) => {
          this.alertService.success("Document is Valid.")
        }, (error: any) => {
          this.alertService.error(error.error?.errorDescription)
        });
      }
    
      onDocumentValidateButtonClicked(): void {
        this.validateCurrentDocument();
      }
    
      onSelectionDocumentVersionChanged(): void {
        this.loadDocumentForVersion(this.documentForm.controls['payloadVersion'].value)
      }
    
      public onEditPanelClick() {
        if (this.codemirror.codeMirror.hasFocus()) {
          return;
        }
        let endPosition: number = this._document?.payload?.length;
        if (endPosition) {
          // forward focus to "codeMirror"
          this.codemirror.codeMirror.setCursor(endPosition)
        }
        this.codemirror.codeMirror.focus()
    
      }
    
      get getDocumentVersions(): number[] {
        return !this._document?.allVersions ? [] : this._document?.allVersions;
      }
    
      get emptyDocument(): boolean{
        return !this.documentForm.controls['payload']?.value
      }
    
      get documentVersionsExists(): boolean{
        return this.getDocumentVersions.length > 0
      }
    
      get cancelButtonDisabled(): boolean {
        return !this.documentForm.dirty;
      }
    
      get saveButtonDisabled(): boolean {
        return !this.documentForm.dirty || !this.documentForm.controls['payload']?.value;
      }
    
      isDirty(): boolean {
        return this.documentForm.dirty
      }
    
      get showWizardDialog(): boolean {
        // in version DomiSMP 5.0 CR show only the wizard for edelivery-oasis-smp-1.0-servicegroup
        return this._resource?.resourceTypeIdentifier === 'edelivery-oasis-smp-1.0-servicegroup';
      }
    }