Skip to content

Commit

Permalink
record-editor: open backoffice workflows in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
karolina-siemieniuk-morawska committed Sep 26, 2024
1 parent 60d5c5f commit dee799f
Show file tree
Hide file tree
Showing 23 changed files with 624 additions and 15 deletions.
2 changes: 1 addition & 1 deletion backend/data/records/jobs/1813119.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
}
],
"deadline_date": "2024-09-20",
"deadline_date": "2025-09-20",
"control_number": 1813119,
"contact_details": [
{
Expand Down
2 changes: 0 additions & 2 deletions record-editor/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { APP_BASE_HREF } from '@angular/common';
import { HttpModule } from '@angular/http';
import { FormsModule } from '@angular/forms';

import { AccordionModule } from 'ngx-bootstrap/accordion';
import { ToastrModule } from 'ngx-toastr';
import { JsonEditorModule } from 'ng2-json-editor';

import { environment } from '../environments/environment';
import { AppRouter } from './app.router';
Expand Down
5 changes: 5 additions & 0 deletions record-editor/src/app/app.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const appRoutes: Routes = [
loadChildren:
'./holdingpen-editor/holdingpen-editor.module#HoldingpenEditorModule',
},
{
path: 'backoffice',
loadChildren:
'./backoffice-editor/backoffice-editor.module#BackofficeEditorModule',
},
{
path: 'record',
loadChildren: './record-editor/record-editor.module#RecordEditorModule',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<ng-template let-reference="item" #referenceTemplate>
<re-reference-brief [reference]="reference"></re-reference-brief>
</ng-template>

<ng-template let-author="item" #authorTemplate>
<re-author-brief [author]="author"></re-author-brief>
</ng-template>

<ng-template let-item="item" #affiliationAutocompleteTemplate>
<re-affiliation-brief [affiliation]="item._source"></re-affiliation-brief>
</ng-template>

<ng-template #refActionsTemplate>
<div class="row">
<div class="col-md-6">
<re-ref-extract-actions></re-ref-extract-actions>
</div>
<div class="col-md-6">
<re-link-references-button></re-link-references-button>
</div>
</div>
</ng-template>

<ng-template #authorExtractTemplate>
<re-author-extract-actions></re-author-extract-actions>
</ng-template>

<ng-template #fileUploadButtonTemplate>
<re-file-upload-button></re-file-upload-button>
</ng-template>

<re-holdingpen-toolbar [backoffice]="true"></re-holdingpen-toolbar>
<div id="editor-container">
<json-editor *ngIf="workflowObject && schema" [record]="workflowObject.metadata" (recordChange)="onWorkflowMetadataChange($event)"
[(jsonPatches)]="workflowExtraData.conflicts" [schema]="schema" [config]="config" [problemMap]="workflowProblems"
(validationProblems)="onValidationProblems($event)" [templates]="{
referenceTemplate: referenceTemplate,
authorTemplate: authorTemplate,
affiliationAutocompleteTemplate: affiliationAutocompleteTemplate,
refActionsTemplate: refActionsTemplate,
authorExtractTemplate: authorExtractTemplate,
patchesHeaderTemplate: patchesHeaderTemplate,
fileUploadButtonTemplate: fileUploadButtonTemplate
}">
</json-editor>
</div>
104 changes: 104 additions & 0 deletions record-editor/src/app/backoffice-editor/backoffice-editor.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* This file is part of record-editor.
* Copyright (C) 2016 CERN.
*
* record-editor is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* record-editor is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with record-editor; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* In applying this license, CERN does not
* waive the privileges and immunities granted to it by virtue of its status
* as an Intergovernmental Organization or submit itself to any jurisdiction.
*/

import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { SchemaValidationProblems } from 'ng2-json-editor';

import {
BackofficeApiService,
AppConfigService,
GlobalAppStateService,
WorkflowErrorConverterService,
} from '../core/services';
import { SubscriberComponent } from '../shared/classes';
import { WorkflowObject } from '../shared/interfaces';

@Component({
templateUrl: './backoffice-editor.component.html',
styleUrls: [
'../record-editor/json-editor-wrapper/json-editor-wrapper.component.scss',
],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BackofficeEditorComponent
extends SubscriberComponent
implements OnInit {
workflowObject: WorkflowObject;
schema: Object;
config: Object;
workflowProblems: SchemaValidationProblems;
uuid: string;

constructor(
private route: ActivatedRoute,
private apiService: BackofficeApiService,
private appConfigService: AppConfigService,
private globalAppStateService: GlobalAppStateService,
private workflowErrorConverterService: WorkflowErrorConverterService
) {
super();
}

ngOnInit(): void {
this.route.params.takeUntil(this.isDestroyed).subscribe(async (params) => {
this.uuid = params['uuid'];

this.workflowObject = await this.apiService.fetchWorkflowObject(
this.uuid
) as WorkflowObject;
this.schema = await this.apiService.fetchSchema();
this.setWorkflowProblems();
this.globalAppStateService.jsonBeingEdited$.next(this.workflowObject);
this.globalAppStateService.isJsonUpdated$.next(false);
this.config = this.appConfigService.getConfigForRecord(
this.workflowObject.metadata
);
});
}

private setWorkflowProblems() {
const errors = this.workflowExtraData.validation_errors;
if (errors && errors.length > 0) {
this.workflowProblems =
this.workflowErrorConverterService.toValidationProblems(errors);
} else {
this.workflowProblems = {};
}
}

get workflowExtraData() {
return this.workflowObject._extra_data || {};
}

onValidationProblems(problems: SchemaValidationProblems) {
this.globalAppStateService.validationProblems$.next(problems);
}

onWorkflowMetadataChange(metadata: object) {
const workflowObject = Object.assign({}, this.workflowObject, {
metadata,
});
this.globalAppStateService.jsonBeingEdited$.next(workflowObject);
this.globalAppStateService.isJsonUpdated$.next(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of record-editor.
* Copyright (C) 2017 CERN.
*
* record-editor is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* record-editor is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with record-editor; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* In applying this license, CERN does not
* waive the privileges and immunities granted to it by virtue of its status
* as an Intergovernmental Organization or submit itself to any jurisdiction.
*/

import { NgModule } from '@angular/core';

import { BackofficeEditorRouter } from './backoffice.router';

import { BackofficeEditorComponent } from './backoffice-editor.component';

import { SharedModule } from '../shared';
import { HoldingpenEditorModule } from '../holdingpen-editor/holdingpen-editor.module';

@NgModule({
imports: [SharedModule, BackofficeEditorRouter, HoldingpenEditorModule],
declarations: [BackofficeEditorComponent],
})
export class BackofficeEditorModule {}
14 changes: 14 additions & 0 deletions record-editor/src/app/backoffice-editor/backoffice.router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Routes, RouterModule } from '@angular/router';
import { NgModule } from '@angular/core';

import { BackofficeEditorComponent } from './backoffice-editor.component';

const backofficeEditorRoutes: Routes = [
{ path: ':uuid', component: BackofficeEditorComponent },
];

@NgModule({
imports: [RouterModule.forChild(backofficeEditorRoutes)],
exports: [RouterModule],
})
export class BackofficeEditorRouter {}
19 changes: 19 additions & 0 deletions record-editor/src/app/core/services/backoffice-api-auth.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Http } from '@angular/http';
import { Injectable } from '@angular/core';

import { CommonApiService } from './common-api.service';
import { backofficeApiUrl } from '../../shared/config';

@Injectable()
export class BackofficeApiAuthService extends CommonApiService {
constructor(protected http: Http) {
super(http);
}

refreshToken(refreshToken: string): Promise<{ access: string }> {
return this.http
.post(`${backofficeApiUrl}/token/refresh/`, { refresh: refreshToken })
.map((res) => res.json())
.toPromise();
}
}
Loading

0 comments on commit dee799f

Please sign in to comment.