forked from inspirehep/inspirehep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
record-editor: open backoffice workflows in editor
* ref: cern-sis/issues-inspire#538
- Loading branch information
1 parent
60d5c5f
commit dee799f
Showing
23 changed files
with
624 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
record-editor/src/app/backoffice-editor/backoffice-editor.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
104
record-editor/src/app/backoffice-editor/backoffice-editor.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
record-editor/src/app/backoffice-editor/backoffice-editor.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
record-editor/src/app/backoffice-editor/backoffice.router.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
record-editor/src/app/core/services/backoffice-api-auth.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.