Skip to content
This repository was archived by the owner on Nov 19, 2020. It is now read-only.
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@angular/router": "^4.0.0",
"core-js": "^2.4.1",
"font-awesome": "^4.7.0",
"idlejs": "^2.0.0",
"immutable": "^3.8.1",
"lodash": "4.17.2",
"ng2-json-editor": "^0.24.0",
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class RavenErrorHandler implements ErrorHandler {
BrowserAnimationsModule, // needed for ToastrModule
HttpModule,
AppRouter,
// feature-modules

CoreModule, // all core services
AccordionModule.forRoot(),
// ngx-toastr
Expand Down
5 changes: 4 additions & 1 deletion src/app/app.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { NgModule } from '@angular/core';
const appRoutes: Routes = [
{ path: 'holdingpen', loadChildren: './holdingpen-editor/holdingpen-editor.module#HoldingpenEditorModule' },
{ path: 'record', loadChildren: './record-editor/record-editor.module#RecordEditorModule' },
{ path: 'multieditor', loadChildren: './multi-editor/multi-editor.module#MultiEditorModule' }
{ path: 'multieditor', loadChildren: './multi-editor/multi-editor.module#MultiEditorModule' },
{ path: 'error', loadChildren: './error/error.module#ErrorModule' },
{ path: '**', pathMatch: 'full', redirectTo: 'error' }

];

@NgModule({
Expand Down
5 changes: 3 additions & 2 deletions src/app/core/services/global-app-state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@

import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { ReplaySubject } from 'rxjs/ReplaySubject';
import { SchemaValidationProblems } from 'ng2-json-editor';

import { editorConfigs } from '../../shared/config';
import { onDocumentTypeChange } from '../../shared/config/hep';

@Injectable()
export class GlobalAppStateService {
readonly jsonBeingEdited$ = new Subject<object>();
readonly jsonBeingEdited$ = new ReplaySubject<object>(1);

readonly isJsonUpdated$ = new Subject<boolean>();
readonly isJsonUpdated$ = new ReplaySubject<boolean>(1);

readonly validationProblems$ = new Subject<SchemaValidationProblems>();
readonly hasAnyValidationProblem$ = this.validationProblems$
Expand Down
53 changes: 34 additions & 19 deletions src/app/core/services/record-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import { Observable } from 'rxjs/Observable';
import { environment } from '../../../environments/environment';
import { AppConfigService } from './app-config.service';
import { CommonApiService } from './common-api.service';
import { Ticket, RecordRevision } from '../../shared/interfaces';
import { Ticket, RecordRevision, RecordResources } from '../../shared/interfaces';
import { ApiError } from '../../shared/classes';
import { editorApiUrl, apiUrl } from '../../shared/config';

@Injectable()
export class RecordApiService extends CommonApiService {

private currentRecordApiUrl: string;
private currentRecordSaveApiUrl: string;
private currentRecordEditorApiUrl: string;
private currentRecordId: string;

Expand All @@ -48,29 +48,44 @@ export class RecordApiService extends CommonApiService {
super(http);
}

checkEditorPermission(pidType: string, pidValue: string): Promise<any> {
this.currentRecordEditorApiUrl = `${editorApiUrl}/${pidType}/${pidValue}`;
return this.http
.get(`${this.currentRecordEditorApiUrl}/permission`)
.toPromise();
}

fetchRecord(pidType: string, pidValue: string): Promise<Object> {
fetchRecordResources(pidType: string, pidValue: string): Observable<RecordResources> {
if (this.currentRecordEditorApiUrl) {
this.unlockRecord();
}
this.currentRecordId = pidValue;
this.currentRecordApiUrl = `${apiUrl}/${pidType}/${pidValue}/db`;
this.currentRecordSaveApiUrl = `${apiUrl}/${pidType}/${pidValue}/db`;
this.currentRecordEditorApiUrl = `${editorApiUrl}/${pidType}/${pidValue}`;
// TODO: remove this side effect when every action done in resolvers
this.newRecordFetched$.next(null);
return this.fetchUrl(this.currentRecordApiUrl);
return this.http
.get(this.currentRecordEditorApiUrl)
.map(res => res.json())
.catch(error => Observable.throw(new ApiError(error)));

}

saveRecord(record: object): Observable<void> {
return this.http
.put(this.currentRecordApiUrl, record)
.put(this.currentRecordSaveApiUrl, record)
.catch(error => Observable.throw(new ApiError(error)));
}

fetchRecordTickets(): Promise<Array<Ticket>> {
return this.fetchUrl(`${this.currentRecordEditorApiUrl}/rt/tickets`);
lockRecord() {
this.http
.post(`${this.currentRecordEditorApiUrl}/lock/lock`, null)
.subscribe();
}

unlockRecord() {
this.http
.post(`${this.currentRecordEditorApiUrl}/lock/unlock`, null)
.subscribe();
}

fetchRecordTickets(): Observable<Array<Ticket>> {
return this.http
.get(`${this.currentRecordEditorApiUrl}/rt/tickets`)
.map(res => res.json());
}

createRecordTicket(ticket: Ticket): Promise<{ id: string, link: string }> {
Expand Down Expand Up @@ -100,11 +115,10 @@ export class RecordApiService extends CommonApiService {
.map((queues: Array<{ name: string }>) => queues.map(queue => queue.name));
}

fetchRevisions(): Promise<Array<RecordRevision>> {
fetchRevisions(): Observable<Array<RecordRevision>> {
return this.http
.get(`${this.currentRecordEditorApiUrl}/revisions`)
.map(res => res.json())
.toPromise();
.map(res => res.json());
}

fetchRevisionData(transactionId: number, recUUID: string): Promise<Object> {
Expand All @@ -125,7 +139,8 @@ export class RecordApiService extends CommonApiService {
return this.http
.get(`${apiUrl}/${recordType}/?q=${query}&size=200`, { headers: this.returnOnlyIdsHeaders })
.map(res => res.json())
.map(json => json.hits.recids);
.map(json => json.hits.recids)
.catch(error => Observable.throw(new ApiError(error)));
}

preview(record: object): Promise<string> {
Expand Down
24 changes: 16 additions & 8 deletions src/app/core/services/record-search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,27 @@ import { RecordApiService } from './record-api.service';
@Injectable()
export class RecordSearchService {
readonly resultCount$ = new ReplaySubject<number>(1);
readonly cursor$ = new ReplaySubject<number>(1);

private lastSearchResult: Array<number>;
private lastSearchQuery: string;

constructor(private apiService: RecordApiService) { }

/**
* Performs search with side effect and simple caching
*/
search(recordType: string, query: string): Observable<Array<number>> {
return this.apiService.searchRecord(recordType, query)
.do(results => {
this.resultCount$.next(results.length);
this.cursor$.next(0);
if (query === this.lastSearchQuery) {
return Observable.of(this.lastSearchResult);
}

return this.apiService
.searchRecord(recordType, query)
.do((foundIds) => {
this.lastSearchResult = foundIds;
this.lastSearchQuery = query;
this.resultCount$.next(foundIds.length);
});
}

setCursor(cursor: number) {
this.cursor$.next(cursor);
}
}
47 changes: 47 additions & 0 deletions src/app/error/error.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This file is part of record-editor.
* Copyright (C) 2018 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 { SharedModule } from '../shared';

import { ErrorRouter } from './error.router';
import { NotFoundComponent } from './not-found';
import { ForbiddenComponent } from './forbidden';
import { LockedComponent } from './locked';
import { InternalServerErrorComponent } from './internal-server-error';



@NgModule({
imports: [
SharedModule,
ErrorRouter
],
declarations: [
NotFoundComponent,
ForbiddenComponent,
LockedComponent,
InternalServerErrorComponent
]
})
export class ErrorModule { }
25 changes: 25 additions & 0 deletions src/app/error/error.router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Routes, RouterModule } from '@angular/router';
import { NgModule } from '@angular/core';

import { NotFoundComponent } from './not-found';
import { ForbiddenComponent } from './forbidden';
import { LockedComponent } from './locked';
import { InternalServerErrorComponent } from './internal-server-error';

const errorRoutes: Routes = [
{ path: '', redirectTo: '404' },
{ path: '403', component: ForbiddenComponent },
{ path: '404', component: NotFoundComponent },
{ path: '423', component: LockedComponent },
{ path: '500', component: InternalServerErrorComponent }
];

@NgModule({
imports: [
RouterModule.forChild(errorRoutes)
],
exports: [
RouterModule,
]
})
export class ErrorRouter { }
1 change: 1 addition & 0 deletions src/app/error/forbidden/forbidden.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Forbidden</p>
30 changes: 30 additions & 0 deletions src/app/error/forbidden/forbidden.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is part of record-editor.
* Copyright (C) 2018 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 } from '@angular/core';

@Component({
selector: 're-forbidden',
templateUrl: './forbidden.component.html',
styleUrls: ['./forbidden.component.scss']
})
export class ForbiddenComponent { }
1 change: 1 addition & 0 deletions src/app/error/forbidden/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ForbiddenComponent } from './forbidden.component';
1 change: 1 addition & 0 deletions src/app/error/internal-server-error/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { InternalServerErrorComponent } from './internal-server-error.component';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Internal Server Error</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is part of record-editor.
* Copyright (C) 2018 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 } from '@angular/core';

@Component({
selector: 're-internal-server-error',
templateUrl: './internal-server-error.component.html',
styleUrls: ['./internal-server-error.component.scss']
})
export class InternalServerErrorComponent { }
1 change: 1 addition & 0 deletions src/app/error/locked/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { LockedComponent } from './locked.component';
1 change: 1 addition & 0 deletions src/app/error/locked/locked.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Locked</p>
Empty file.
30 changes: 30 additions & 0 deletions src/app/error/locked/locked.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is part of record-editor.
* Copyright (C) 2018 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 } from '@angular/core';

@Component({
selector: 're-locked',
templateUrl: './locked.component.html',
styleUrls: ['./locked.component.scss']
})
export class LockedComponent { }
1 change: 1 addition & 0 deletions src/app/error/not-found/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { NotFoundComponent } from './not-found.component';
1 change: 1 addition & 0 deletions src/app/error/not-found/not-found.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Not found</p>
Empty file.
Loading