diff --git a/dmp-admin/src/app/app.component.html b/dmp-admin/src/app/app.component.html index 8033861af..fb3975929 100644 --- a/dmp-admin/src/app/app.component.html +++ b/dmp-admin/src/app/app.component.html @@ -42,7 +42,7 @@ - + \ No newline at end of file diff --git a/dmp-admin/src/app/app.module.ts b/dmp-admin/src/app/app.module.ts index a1ff61f0b..e262b5ab5 100644 --- a/dmp-admin/src/app/app.module.ts +++ b/dmp-admin/src/app/app.module.ts @@ -67,6 +67,7 @@ import { DatasetprofileEditorComponent } from './managers/datasetprofile-editor/ import { DatasetProfileGUIEditorComponent } from './dataset-profile-gui-editor/dataset-profile-gui-editor.component'; import { DatasetProfileModule } from './dataset-profile-form/dataset-profile.module'; +import { UnauthorizedModule } from './unauthorized/unauthorized.module'; // import { FieldFormComponent } from './dataset-profile-form/field-form/field-form.component'; // import { FormComponent } from './dataset-profile-form/form/form.component'; diff --git a/dmp-admin/src/app/routes.ts b/dmp-admin/src/app/routes.ts index 0a08a6da1..b6e651cfe 100644 --- a/dmp-admin/src/app/routes.ts +++ b/dmp-admin/src/app/routes.ts @@ -11,7 +11,9 @@ import { DatasetprofileEditorComponent } from './managers/datasetprofile-editor/ import { MainWindowComponent } from './main-window/main-window.component'; import { NgModule } from '@angular/core'; import { AuthGuard } from './guards/auth.guard'; - +import { AppComponent } from 'app/app.component'; +import { MainSignInComponent } from 'app/login/main-sign-in/main-sign-in.component'; +import { UnauthorizedComponent } from './unauthorized/unauthorized.component'; // Route Configuration @@ -19,9 +21,14 @@ const routes: Routes = [ { path: '', - redirectTo: 'app-root', + redirectTo: '/main', pathMatch: 'full' }, + { + path: 'app-root', + component: AppComponent, + canActivate: [AuthGuard] + }, { path: 'datasets', component: DatasetsViewerComponent, @@ -43,7 +50,9 @@ const routes: Routes = [ component: MainWindowComponent, canActivate: [AuthGuard] }, - { path: 'form', loadChildren: './dataset-profile-form/dataset-profile.module#DatasetProfileModule', canActivate: [AuthGuard]} + { path: 'form', loadChildren: './dataset-profile-form/dataset-profile.module#DatasetProfileModule', canActivate: [AuthGuard]}, + { path: "unauthorized", loadChildren: './unauthorized/unauthorized.module#UnauthorizedModule' } , + { path: "login", component: MainSignInComponent } ]; @NgModule({ @@ -56,7 +65,7 @@ const routes: Routes = [ RouterModule ], providers: [ - + AuthGuard ] }) diff --git a/dmp-admin/src/app/services/auth/auth.service.ts b/dmp-admin/src/app/services/auth/auth.service.ts index 2ee468aab..c0da3a854 100644 --- a/dmp-admin/src/app/services/auth/auth.service.ts +++ b/dmp-admin/src/app/services/auth/auth.service.ts @@ -30,7 +30,10 @@ export class AuthService { this.headers = this.headers.set('Accept', 'application/json'); } - + private clear(): void { + localStorage.removeItem('principal'); + } + public current(principal?: Principal): Principal { if (principal) { localStorage.setItem('principal', JSON.stringify(principal)); @@ -40,7 +43,30 @@ export class AuthService { if (!principalJson) { return null; } const principalObj = JSON.parse(principalJson) as Principal; return principalObj; - } + } + + public me(): Observable { + const url = this.actionUrl + '/me'; + const principal = this.current(); + if (!principal) { + this.clear(); + return Observable.of(); + } + let headers = this.headers; + headers = headers.set('AuthToken', principal.token) + return this.http.post(url, null, { headers: headers }) + .map((res: any) => { + const princ = this.current(JsonSerializer.fromJSONObject(res.payload, Principal)); + return princ; + }) + .catch((error: any) => { + console.warn('could not retrieve me info:\n', error); + this.clear(); + const princ = this.current(); + this.router.navigate(['/login']); + return Observable.of(princ); + }); + } public nativeLogin(credentials: Credential): Observable { debugger; const url = this.actionUrl + 'nativelogin'; diff --git a/dmp-admin/src/app/unauthorized/unauthorized.component.html b/dmp-admin/src/app/unauthorized/unauthorized.component.html new file mode 100644 index 000000000..1a1112d35 --- /dev/null +++ b/dmp-admin/src/app/unauthorized/unauthorized.component.html @@ -0,0 +1 @@ +

{{message}}

\ No newline at end of file diff --git a/dmp-admin/src/app/unauthorized/unauthorized.component.js.map b/dmp-admin/src/app/unauthorized/unauthorized.component.js.map new file mode 100644 index 000000000..c61b89104 --- /dev/null +++ b/dmp-admin/src/app/unauthorized/unauthorized.component.js.map @@ -0,0 +1 @@ +{"version":3,"file":"unauthorized.component.js","sourceRoot":"","sources":["unauthorized.component.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAMzD,IAAa,qBAAqB;IAG9B,+BACY,WAAwB,EACxB,KAAqB,EACrB,MAAc;QAFd,gBAAW,GAAX,WAAW,CAAa;QACxB,UAAK,GAAL,KAAK,CAAgB;QACrB,WAAM,GAAN,MAAM,CAAQ;IACtB,CAAC;IAEL,+CAAe,GAAf;QAAA,iBAaC;QAZG,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC;QACpE,IAAI,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QAC3C,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,WAAW,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;QAChF,CAAC;QACD,IAAI,CAAC,CAAC;YACF,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC,SAAS,CAC3B,UAAA,SAAS;gBACL,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;oBAAC,KAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,WAAW,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;YAChG,CAAC,EACD,UAAA,GAAG,IAAI,OAAA,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,GAAG,CAAC,EAAvC,CAAuC,CAAC,CAAC;QACxD,CAAC;IACL,CAAC;IACL,4BAAC;AAAD,CAAC,AAvBD,IAuBC;AArBG;IADC,KAAK,EAAE;;sDACe;AAFd,qBAAqB;IAJjC,SAAS,CAAC;QACP,QAAQ,EAAE,wBAAwB;QAClC,WAAW,EAAE,+BAA+B;KAC/C,CAAC;qCAK2B,WAAW;QACjB,cAAc;QACb,MAAM;GANjB,qBAAqB,CAuBjC;SAvBY,qBAAqB"} \ No newline at end of file diff --git a/dmp-admin/src/app/unauthorized/unauthorized.component.ts b/dmp-admin/src/app/unauthorized/unauthorized.component.ts new file mode 100644 index 000000000..f8c067519 --- /dev/null +++ b/dmp-admin/src/app/unauthorized/unauthorized.component.ts @@ -0,0 +1,33 @@ +import { AuthService } from '../services/auth/auth.service'; +import { Component, Input } from "@angular/core"; +import { ActivatedRoute, Router } from "@angular/router"; + +@Component({ + selector: 'unauthorized-component', + templateUrl: './unauthorized.component.html' +}) +export class UnauthorizedComponent { + @Input() + public message: string; + constructor( + private authService: AuthService, + private route: ActivatedRoute, + private router: Router + ) { } + + ngAfterViewInit() { + let returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/'; + let principal = this.authService.current(); + if (!principal) { + this.router.navigate(['/login'], { queryParams: { returnUrl: returnUrl } }); + } + else { + this.authService.me().subscribe( + principal => { + if (!principal) this.router.navigate(['/login'], { queryParams: { returnUrl: returnUrl } }); + else this.router.navigate(["/"]) + }, + err => console.error('An error occurred', err)); + } + } +} \ No newline at end of file diff --git a/dmp-admin/src/app/unauthorized/unauthorized.module.js.map b/dmp-admin/src/app/unauthorized/unauthorized.module.js.map new file mode 100644 index 000000000..126948b9d --- /dev/null +++ b/dmp-admin/src/app/unauthorized/unauthorized.module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"unauthorized.module.js","sourceRoot":"","sources":["unauthorized.module.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAmBtD,IAAa,kBAAkB;IAA/B;IAAkC,CAAC;IAAD,yBAAC;AAAD,CAAC,AAAnC,IAAmC;AAAtB,kBAAkB;IAlB9B,QAAQ,CAAC;QACN,OAAO,EAAE;YACL,YAAY;YACZ,WAAW;YACX,gBAAgB;YAChB,kBAAkB;YAClB,YAAY;SACf;QAED,YAAY,EAAE;YACV,qBAAqB;SACxB;QAED,OAAO,EAAE;YACL,qBAAqB;SACxB;KACJ,CAAC;GAEW,kBAAkB,CAAI;SAAtB,kBAAkB"} \ No newline at end of file diff --git a/dmp-admin/src/app/unauthorized/unauthorized.module.ts b/dmp-admin/src/app/unauthorized/unauthorized.module.ts new file mode 100644 index 000000000..5929b9ed7 --- /dev/null +++ b/dmp-admin/src/app/unauthorized/unauthorized.module.ts @@ -0,0 +1,29 @@ +import { CommonModule } from '@angular/common'; +import { HttpClientModule } from '@angular/common/http'; +import { NgModule } from '@angular/core'; +import { FormsModule } from '@angular/forms'; + +import { RouterModule } from '@angular/router'; + +import { UnauthorizedComponent } from './unauthorized.component'; +import { UnauthorizedRoutes } from './unauthorized.routes'; +//import { SharedModule } from '../shared/shared.module' +@NgModule({ + imports: [ + CommonModule, + FormsModule, + HttpClientModule, + UnauthorizedRoutes + // SharedModule + ], + + declarations: [ + UnauthorizedComponent + ], + + exports: [ + UnauthorizedComponent + ] +}) + +export class UnauthorizedModule { } diff --git a/dmp-admin/src/app/unauthorized/unauthorized.routes.js.map b/dmp-admin/src/app/unauthorized/unauthorized.routes.js.map new file mode 100644 index 000000000..8a1dbc929 --- /dev/null +++ b/dmp-admin/src/app/unauthorized/unauthorized.routes.js.map @@ -0,0 +1 @@ +{"version":3,"file":"unauthorized.routes.js","sourceRoot":"","sources":["unauthorized.routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAU,MAAM,iBAAiB,CAAC;AAEvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,IAAM,MAAM,GAAW;IACnB,EAAE,IAAI,EAAE,EAAE,EAAE,SAAS,EAAE,qBAAqB,EAAE;CACjD,CAAC;AAEF,MAAM,CAAC,IAAM,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC"} \ No newline at end of file diff --git a/dmp-admin/src/app/unauthorized/unauthorized.routes.ts b/dmp-admin/src/app/unauthorized/unauthorized.routes.ts new file mode 100644 index 000000000..f8e4ebee4 --- /dev/null +++ b/dmp-admin/src/app/unauthorized/unauthorized.routes.ts @@ -0,0 +1,9 @@ +import { RouterModule, Routes } from '@angular/router'; + +import { UnauthorizedComponent } from './unauthorized.component'; + +const routes: Routes = [ + { path: '', component: UnauthorizedComponent } +]; + +export const UnauthorizedRoutes = RouterModule.forChild(routes); diff --git a/dmp-frontend/package-lock.json b/dmp-frontend/package-lock.json index 7c25c48da..f97b8e9ad 100644 --- a/dmp-frontend/package-lock.json +++ b/dmp-frontend/package-lock.json @@ -1234,6 +1234,7 @@ "requires": { "anymatch": "1.3.2", "async-each": "1.0.1", + "fsevents": "1.1.3", "glob-parent": "2.0.0", "inherits": "2.0.3", "is-binary-path": "1.0.1", @@ -2829,6 +2830,910 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, + "fsevents": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.1.3.tgz", + "integrity": "sha512-WIr7iDkdmdbxu/Gh6eKEZJL6KPE74/5MEsf2whTOFNxbIoIixogroLdKYqB6FDav4Wavh/lZdzzd3b2KxIXC5Q==", + "dev": true, + "optional": true, + "requires": { + "nan": "2.8.0", + "node-pre-gyp": "0.6.39" + }, + "dependencies": { + "abbrev": { + "version": "1.1.0", + "bundled": true, + "dev": true, + "optional": true + }, + "ajv": { + "version": "4.11.8", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "co": "4.6.0", + "json-stable-stringify": "1.0.1" + } + }, + "ansi-regex": { + "version": "2.1.1", + "bundled": true, + "dev": true + }, + "aproba": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "are-we-there-yet": { + "version": "1.1.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "delegates": "1.0.0", + "readable-stream": "2.2.9" + } + }, + "asn1": { + "version": "0.2.3", + "bundled": true, + "dev": true, + "optional": true + }, + "assert-plus": { + "version": "0.2.0", + "bundled": true, + "dev": true, + "optional": true + }, + "asynckit": { + "version": "0.4.0", + "bundled": true, + "dev": true, + "optional": true + }, + "aws-sign2": { + "version": "0.6.0", + "bundled": true, + "dev": true, + "optional": true + }, + "aws4": { + "version": "1.6.0", + "bundled": true, + "dev": true, + "optional": true + }, + "balanced-match": { + "version": "0.4.2", + "bundled": true, + "dev": true + }, + "bcrypt-pbkdf": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "tweetnacl": "0.14.5" + } + }, + "block-stream": { + "version": "0.0.9", + "bundled": true, + "dev": true, + "requires": { + "inherits": "2.0.3" + } + }, + "boom": { + "version": "2.10.1", + "bundled": true, + "dev": true, + "requires": { + "hoek": "2.16.3" + } + }, + "brace-expansion": { + "version": "1.1.7", + "bundled": true, + "dev": true, + "requires": { + "balanced-match": "0.4.2", + "concat-map": "0.0.1" + } + }, + "buffer-shims": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "caseless": { + "version": "0.12.0", + "bundled": true, + "dev": true, + "optional": true + }, + "co": { + "version": "4.6.0", + "bundled": true, + "dev": true, + "optional": true + }, + "code-point-at": { + "version": "1.1.0", + "bundled": true, + "dev": true + }, + "combined-stream": { + "version": "1.0.5", + "bundled": true, + "dev": true, + "requires": { + "delayed-stream": "1.0.0" + } + }, + "concat-map": { + "version": "0.0.1", + "bundled": true, + "dev": true + }, + "console-control-strings": { + "version": "1.1.0", + "bundled": true, + "dev": true + }, + "core-util-is": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "cryptiles": { + "version": "2.0.5", + "bundled": true, + "dev": true, + "requires": { + "boom": "2.10.1" + } + }, + "dashdash": { + "version": "1.14.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "debug": { + "version": "2.6.8", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ms": "2.0.0" + } + }, + "deep-extend": { + "version": "0.4.2", + "bundled": true, + "dev": true, + "optional": true + }, + "delayed-stream": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "delegates": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "detect-libc": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "ecc-jsbn": { + "version": "0.1.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "jsbn": "0.1.1" + } + }, + "extend": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "extsprintf": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "forever-agent": { + "version": "0.6.1", + "bundled": true, + "dev": true, + "optional": true + }, + "form-data": { + "version": "2.1.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "asynckit": "0.4.0", + "combined-stream": "1.0.5", + "mime-types": "2.1.15" + } + }, + "fs.realpath": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "fstream": { + "version": "1.0.11", + "bundled": true, + "dev": true, + "requires": { + "graceful-fs": "4.1.11", + "inherits": "2.0.3", + "mkdirp": "0.5.1", + "rimraf": "2.6.1" + } + }, + "fstream-ignore": { + "version": "1.0.5", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "fstream": "1.0.11", + "inherits": "2.0.3", + "minimatch": "3.0.4" + } + }, + "gauge": { + "version": "2.7.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "aproba": "1.1.1", + "console-control-strings": "1.1.0", + "has-unicode": "2.0.1", + "object-assign": "4.1.1", + "signal-exit": "3.0.2", + "string-width": "1.0.2", + "strip-ansi": "3.0.1", + "wide-align": "1.1.2" + } + }, + "getpass": { + "version": "0.1.7", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "glob": { + "version": "7.1.2", + "bundled": true, + "dev": true, + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "graceful-fs": { + "version": "4.1.11", + "bundled": true, + "dev": true + }, + "har-schema": { + "version": "1.0.5", + "bundled": true, + "dev": true, + "optional": true + }, + "har-validator": { + "version": "4.2.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ajv": "4.11.8", + "har-schema": "1.0.5" + } + }, + "has-unicode": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "hawk": { + "version": "3.1.3", + "bundled": true, + "dev": true, + "requires": { + "boom": "2.10.1", + "cryptiles": "2.0.5", + "hoek": "2.16.3", + "sntp": "1.0.9" + } + }, + "hoek": { + "version": "2.16.3", + "bundled": true, + "dev": true + }, + "http-signature": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "0.2.0", + "jsprim": "1.4.0", + "sshpk": "1.13.0" + } + }, + "inflight": { + "version": "1.0.6", + "bundled": true, + "dev": true, + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "bundled": true, + "dev": true + }, + "ini": { + "version": "1.3.4", + "bundled": true, + "dev": true, + "optional": true + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "requires": { + "number-is-nan": "1.0.1" + } + }, + "is-typedarray": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "isarray": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "isstream": { + "version": "0.1.2", + "bundled": true, + "dev": true, + "optional": true + }, + "jodid25519": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "jsbn": "0.1.1" + } + }, + "jsbn": { + "version": "0.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "json-schema": { + "version": "0.2.3", + "bundled": true, + "dev": true, + "optional": true + }, + "json-stable-stringify": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "jsonify": "0.0.0" + } + }, + "json-stringify-safe": { + "version": "5.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "jsonify": { + "version": "0.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "jsprim": { + "version": "1.4.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0", + "extsprintf": "1.0.2", + "json-schema": "0.2.3", + "verror": "1.3.6" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "mime-db": { + "version": "1.27.0", + "bundled": true, + "dev": true + }, + "mime-types": { + "version": "2.1.15", + "bundled": true, + "dev": true, + "requires": { + "mime-db": "1.27.0" + } + }, + "minimatch": { + "version": "3.0.4", + "bundled": true, + "dev": true, + "requires": { + "brace-expansion": "1.1.7" + } + }, + "minimist": { + "version": "0.0.8", + "bundled": true, + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "bundled": true, + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, + "ms": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "node-pre-gyp": { + "version": "0.6.39", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "detect-libc": "1.0.2", + "hawk": "3.1.3", + "mkdirp": "0.5.1", + "nopt": "4.0.1", + "npmlog": "4.1.0", + "rc": "1.2.1", + "request": "2.81.0", + "rimraf": "2.6.1", + "semver": "5.3.0", + "tar": "2.2.1", + "tar-pack": "3.4.0" + } + }, + "nopt": { + "version": "4.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "abbrev": "1.1.0", + "osenv": "0.1.4" + } + }, + "npmlog": { + "version": "4.1.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "are-we-there-yet": "1.1.4", + "console-control-strings": "1.1.0", + "gauge": "2.7.4", + "set-blocking": "2.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "oauth-sign": { + "version": "0.8.2", + "bundled": true, + "dev": true, + "optional": true + }, + "object-assign": { + "version": "4.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "once": { + "version": "1.4.0", + "bundled": true, + "dev": true, + "requires": { + "wrappy": "1.0.2" + } + }, + "os-homedir": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "os-tmpdir": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "osenv": { + "version": "0.1.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "os-homedir": "1.0.2", + "os-tmpdir": "1.0.2" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "performance-now": { + "version": "0.2.0", + "bundled": true, + "dev": true, + "optional": true + }, + "process-nextick-args": { + "version": "1.0.7", + "bundled": true, + "dev": true + }, + "punycode": { + "version": "1.4.1", + "bundled": true, + "dev": true, + "optional": true + }, + "qs": { + "version": "6.4.0", + "bundled": true, + "dev": true, + "optional": true + }, + "rc": { + "version": "1.2.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "deep-extend": "0.4.2", + "ini": "1.3.4", + "minimist": "1.2.0", + "strip-json-comments": "2.0.1" + }, + "dependencies": { + "minimist": { + "version": "1.2.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "readable-stream": { + "version": "2.2.9", + "bundled": true, + "dev": true, + "requires": { + "buffer-shims": "1.0.0", + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "1.0.0", + "process-nextick-args": "1.0.7", + "string_decoder": "1.0.1", + "util-deprecate": "1.0.2" + } + }, + "request": { + "version": "2.81.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "aws-sign2": "0.6.0", + "aws4": "1.6.0", + "caseless": "0.12.0", + "combined-stream": "1.0.5", + "extend": "3.0.1", + "forever-agent": "0.6.1", + "form-data": "2.1.4", + "har-validator": "4.2.1", + "hawk": "3.1.3", + "http-signature": "1.1.1", + "is-typedarray": "1.0.0", + "isstream": "0.1.2", + "json-stringify-safe": "5.0.1", + "mime-types": "2.1.15", + "oauth-sign": "0.8.2", + "performance-now": "0.2.0", + "qs": "6.4.0", + "safe-buffer": "5.0.1", + "stringstream": "0.0.5", + "tough-cookie": "2.3.2", + "tunnel-agent": "0.6.0", + "uuid": "3.0.1" + } + }, + "rimraf": { + "version": "2.6.1", + "bundled": true, + "dev": true, + "requires": { + "glob": "7.1.2" + } + }, + "safe-buffer": { + "version": "5.0.1", + "bundled": true, + "dev": true + }, + "semver": { + "version": "5.3.0", + "bundled": true, + "dev": true, + "optional": true + }, + "set-blocking": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "signal-exit": { + "version": "3.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "sntp": { + "version": "1.0.9", + "bundled": true, + "dev": true, + "requires": { + "hoek": "2.16.3" + } + }, + "sshpk": { + "version": "1.13.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "asn1": "0.2.3", + "assert-plus": "1.0.0", + "bcrypt-pbkdf": "1.0.1", + "dashdash": "1.14.1", + "ecc-jsbn": "0.1.1", + "getpass": "0.1.7", + "jodid25519": "1.0.2", + "jsbn": "0.1.1", + "tweetnacl": "0.14.5" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "string-width": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "requires": { + "code-point-at": "1.1.0", + "is-fullwidth-code-point": "1.0.0", + "strip-ansi": "3.0.1" + } + }, + "string_decoder": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "5.0.1" + } + }, + "stringstream": { + "version": "0.0.5", + "bundled": true, + "dev": true, + "optional": true + }, + "strip-ansi": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "requires": { + "ansi-regex": "2.1.1" + } + }, + "strip-json-comments": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "tar": { + "version": "2.2.1", + "bundled": true, + "dev": true, + "requires": { + "block-stream": "0.0.9", + "fstream": "1.0.11", + "inherits": "2.0.3" + } + }, + "tar-pack": { + "version": "3.4.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "debug": "2.6.8", + "fstream": "1.0.11", + "fstream-ignore": "1.0.5", + "once": "1.4.0", + "readable-stream": "2.2.9", + "rimraf": "2.6.1", + "tar": "2.2.1", + "uid-number": "0.0.6" + } + }, + "tough-cookie": { + "version": "2.3.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "punycode": "1.4.1" + } + }, + "tunnel-agent": { + "version": "0.6.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "safe-buffer": "5.0.1" + } + }, + "tweetnacl": { + "version": "0.14.5", + "bundled": true, + "dev": true, + "optional": true + }, + "uid-number": { + "version": "0.0.6", + "bundled": true, + "dev": true, + "optional": true + }, + "util-deprecate": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "uuid": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "verror": { + "version": "1.3.6", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "extsprintf": "1.0.2" + } + }, + "wide-align": { + "version": "1.1.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "string-width": "1.0.2" + } + }, + "wrappy": { + "version": "1.0.2", + "bundled": true, + "dev": true + } + } + }, "fstream": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.11.tgz", @@ -6456,11 +7361,11 @@ } }, "rxjs": { - "version": "5.4.3", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-5.4.3.tgz", - "integrity": "sha512-fSNi+y+P9ss+EZuV0GcIIqPUK07DEaMRUtLJvdcvMyFjc9dizuDjere+A4V7JrLGnm9iCc+nagV/4QdMTkqC4A==", + "version": "5.5.6", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-5.5.6.tgz", + "integrity": "sha512-v4Q5HDC0FHAQ7zcBX7T2IL6O5ltl1a2GX4ENjPXg6SjDY69Cmx9v4113C99a4wGF16ClPv5Z8mghuYorVkg/kg==", "requires": { - "symbol-observable": "1.0.4" + "symbol-observable": "1.0.1" } }, "safe-buffer": { @@ -7136,9 +8041,9 @@ } }, "symbol-observable": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.0.4.tgz", - "integrity": "sha1-Kb9hXUqnEhvdiYsi1LP5vE4qoD0=" + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.0.1.tgz", + "integrity": "sha1-g0D8RwLDEi310iKI+IKD9RPT/dQ=" }, "tapable": { "version": "0.2.8", diff --git a/dmp-frontend/package.json b/dmp-frontend/package.json index 3ed9b91f0..65c55e415 100644 --- a/dmp-frontend/package.json +++ b/dmp-frontend/package.json @@ -27,7 +27,7 @@ "@ngx-translate/core": "^9.0.1", "@ngx-translate/http-loader": "^2.0.0", "core-js": "^2.4.1", - "rxjs": "^5.4.2", + "rxjs": "5.5.6", "zone.js": "^0.8.17" }, "devDependencies": { diff --git a/dmp-frontend/src/app/app-routing.module.ts b/dmp-frontend/src/app/app-routing.module.ts index a9662d742..b561caae5 100644 --- a/dmp-frontend/src/app/app-routing.module.ts +++ b/dmp-frontend/src/app/app-routing.module.ts @@ -10,6 +10,7 @@ const appRoutes: Routes = [ { path: 'datasets', loadChildren: './datasets/dataset.module#DatasetModule' ,canActivate: [AuthGuard]}, { path: 'projects', loadChildren: './projects/projects.module#ProjectsModule',canActivate: [AuthGuard] }, { path: "dmps", loadChildren: './dmps/dmps.module#DataManagementPlanModule',canActivate: [AuthGuard] }, + { path: 'form', loadChildren: './dataset-profile-form/dataset-profile.module#DatasetProfileModule', canActivate: [AuthGuard]}, { path: 'welcome', component: HomepageComponent, canActivate: [AuthGuard] }, { path: '', redirectTo: '/welcome', pathMatch: 'full' }, { path: "unauthorized", loadChildren: './unauthorized/unauthorized.module#UnauthorizedModule' } diff --git a/dmp-frontend/src/app/app.module.ts b/dmp-frontend/src/app/app.module.ts index cda55cf95..beb768b5a 100644 --- a/dmp-frontend/src/app/app.module.ts +++ b/dmp-frontend/src/app/app.module.ts @@ -30,6 +30,7 @@ import { HomepageComponent } from './homepage/homepage.component'; import { PageNotFoundComponent } from './not-found.component'; import { AppComponent } from './app.component'; import { NgModule } from "@angular/core"; +import { DatasetProfileModule } from './dataset-profile-form/dataset-profile.module'; @NgModule({ diff --git a/dmp-frontend/src/app/dataset-profile-form/compositefield-form/compositefield-form.component.html b/dmp-frontend/src/app/dataset-profile-form/compositefield-form/compositefield-form.component.html new file mode 100644 index 000000000..7424f1e1c --- /dev/null +++ b/dmp-frontend/src/app/dataset-profile-form/compositefield-form/compositefield-form.component.html @@ -0,0 +1,83 @@ +
+ + +
+ +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
Multiplicity
+
+ + +
+ +
+ + +
+
+
+
+ + +
+
+ + +
+
+ +
+
+ + + + + + + +
\ No newline at end of file diff --git a/dmp-frontend/src/app/dataset-profile-form/compositefield-form/compositefield-form.component.ts b/dmp-frontend/src/app/dataset-profile-form/compositefield-form/compositefield-form.component.ts new file mode 100644 index 000000000..b37428bff --- /dev/null +++ b/dmp-frontend/src/app/dataset-profile-form/compositefield-form/compositefield-form.component.ts @@ -0,0 +1,57 @@ +import { Component, Input } from '@angular/core'; +import { FormGroup } from '@angular/forms'; +import { FieldSet } from 'app/models/datasetProfileAdmin/FieldSet'; +import { Field } from 'app/models/datasetProfileAdmin/Field'; +import { FormArray, FormControl } from '@angular/forms'; + +@Component({ + selector: 'compositefield-form', + templateUrl: './compositefield-form.component.html', + styleUrls: [] +}) + +export class CompositeFieldFormComponent { + @Input() form: FormGroup; + @Input() dataModel: FieldSet; + @Input() indexPath: string; + + isComposite: boolean = false; + isMultiplicityEnabled: boolean = false; + + constructon() { } + + ngOnInit() { + //this.addNewField(); + if(this.form.get("multiplicity")) + if (this.form.get("multiplicity").value.min >1 || this.form.get("multiplicity").value.max >1 ) + this.isMultiplicityEnabled= true; + this.isComposite = this.dataModel.fields.length > 1; + } + + onIsCompositeChange(isComposite: boolean) { + if (!isComposite && (this.form.get("fields")).length > 1) { + for(let i = 0; i < (this.form.get("fields")).length - 1; i++) { + (this.form.get("fields")).removeAt(1); + } + this.dataModel.fields.splice(1); + } + } + + onIsMultiplicityEnabledChange(isMultiplicityEnabled: boolean) { + if (!isMultiplicityEnabled) { + (this.form.get('multiplicity').get("min")).setValue(0); + (this.form.get('multiplicity').get("max")).setValue(0); + } + } + + addNewField() { + let field: Field = new Field(); + this.dataModel.fields.push(field); + (this.form.get("fields")).push(field.buildForm()); + } + + DeleteField(index) { + this.dataModel.fields.splice(index, 1); + (this.form.get("fields")).removeAt(index); + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/dataset-profile-form/dataset-profile.module.ts b/dmp-frontend/src/app/dataset-profile-form/dataset-profile.module.ts new file mode 100644 index 000000000..9f71696a9 --- /dev/null +++ b/dmp-frontend/src/app/dataset-profile-form/dataset-profile.module.ts @@ -0,0 +1,77 @@ +import { NgModule } from "@angular/core"; +import { CommonModule } from '@angular/common'; +import { FormsModule,ReactiveFormsModule } from '@angular/forms'; + +import { DatasetProfileRoutes } from "./dataset-profile.router"; +import { RouterModule } from "@angular/router"; + +import { FormComponent } from './form/form.component'; +//import { GroupFieldFormComponent } from './groupfield-form/groupfield-form.component'; +import { RuleFormComponent } from './rule-component/rule.component'; +import { SectionFormComponent } from './section-form/section-form.component'; +import { PageFormComponent } from './page-form/page-component'; +import { CompositeFieldFormComponent } from './compositefield-form/compositefield-form.component'; +import { FieldFormComponent } from './field-form/field-form.component'; +import { HttpClientModule, HttpClient } from "@angular/common/http"; + +import { CheckBoxComponent } from '../shared/componentsAdmin/checkbox/checkbox-component'; +import { FreeTextData } from '../models/DataField/FreeTextData'; +import { BooleanDecisionComponent } from '../shared/componentsAdmin/booleanDecision/booleanDecision-component'; +import { FreeTextComponent } from '../shared/componentsAdmin/freetext/freetext-component'; +import { TextAreaComponent } from '../shared/componentsAdmin/textarea/textarea-component'; +import { RadioBoxComponent } from '../shared/componentsAdmin/radiobox/radiobox-component'; +import { WordlistComponent } from '../shared/componentsAdmin/wordlist/wordlist-component'; +import { AutocompleteComponent } from '../shared/componentsAdmin/autocomplete/autocomplete-component'; +import { ComboboxComponent } from '../shared/componentsAdmin/combobox/combobox-component'; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + HttpClientModule, + ReactiveFormsModule, + RouterModule, + RouterModule.forChild(DatasetProfileRoutes) + ], + + declarations: [ + FormComponent, + //GroupFieldFormComponent, + RuleFormComponent, + SectionFormComponent, + PageFormComponent, + CompositeFieldFormComponent, + FieldFormComponent, + TextAreaComponent, + CheckBoxComponent, + BooleanDecisionComponent, + FreeTextComponent, + ComboboxComponent, + AutocompleteComponent, + WordlistComponent, + RadioBoxComponent + ], + + exports: [ + FormComponent, + //GroupFieldFormComponent, + RuleFormComponent, + SectionFormComponent, + PageFormComponent, + CompositeFieldFormComponent, + FieldFormComponent, + TextAreaComponent, + CheckBoxComponent, + BooleanDecisionComponent, + FreeTextComponent, + ComboboxComponent, + AutocompleteComponent, + WordlistComponent, + RadioBoxComponent + ], + providers:[ + ] +}) + + +export class DatasetProfileModule { } \ No newline at end of file diff --git a/dmp-frontend/src/app/dataset-profile-form/dataset-profile.router.ts b/dmp-frontend/src/app/dataset-profile-form/dataset-profile.router.ts new file mode 100644 index 000000000..44e2337e6 --- /dev/null +++ b/dmp-frontend/src/app/dataset-profile-form/dataset-profile.router.ts @@ -0,0 +1,15 @@ +import { RouterModule, Routes } from '@angular/router'; +import { FormComponent } from 'app/dataset-profile-form/form/form.component'; + +export const DatasetProfileRoutes: Routes = [ + //{ path: "new/:dmpId", component: DatasetWizardComponent, canActivate: [AuthGuard] } + { + path: ':id', + component: FormComponent + }, + { + path: '', + component: FormComponent + } + +]; diff --git a/dmp-frontend/src/app/dataset-profile-form/field-form/field-form.component.html b/dmp-frontend/src/app/dataset-profile-form/field-form/field-form.component.html new file mode 100644 index 000000000..652a20e87 --- /dev/null +++ b/dmp-frontend/src/app/dataset-profile-form/field-form/field-form.component.html @@ -0,0 +1,120 @@ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
Multiplicity
+
+ + +
+ +
+ + +
+
+
+
+ + +
+
+
+ + +
+
+
+ +
+
+ +
+
+ +
+
+
+ + +
+
+
+ {{i + 1}}. Rule {{i + 1}} + +
+ +
+
+
+
+ +
+
+
+
+ + +
\ No newline at end of file diff --git a/dmp-frontend/src/app/dataset-profile-form/field-form/field-form.component.ts b/dmp-frontend/src/app/dataset-profile-form/field-form/field-form.component.ts new file mode 100644 index 000000000..46b97ae94 --- /dev/null +++ b/dmp-frontend/src/app/dataset-profile-form/field-form/field-form.component.ts @@ -0,0 +1,54 @@ + +import { Component, Input } from '@angular/core'; +import { FormGroup, FormControl, FormArray } from '@angular/forms'; +import { ValidationTypes } from '@app/models/common/ValidationTypes'; +import { Field } from '@app/models/datasetProfileAdmin/Field'; +import { Rule } from '@app/models/datasetProfileAdmin/Rule'; + +@Component({ + selector: 'field-form', + templateUrl: './field-form.component.html', + styleUrls: [] +}) + +export class FieldFormComponent { + @Input() form: FormGroup; + @Input() dataModel: Field; + @Input() showMultiplicity: boolean = true; + @Input() indexPath: string; + validationsOptions: Array; + isFieldMultiplicityEnabled: boolean = false; + + constructon() { + } + + ngOnInit() { + if (this.form.get("multiplicity")) + if (this.form.get("multiplicity").value.min > 1 || this.form.get("multiplicity").value.max > 1) + this.isFieldMultiplicityEnabled = true; + this.validationsOptions = [{ key: 0, value: ValidationTypes[0] }, { key: 1, value: ValidationTypes[1] }] + // this.addNewRule(); + } + + onIsFieldMultiplicityEnabledChange(isFieldMultiplicityEnabled: boolean) { + if (!isFieldMultiplicityEnabled) { + (this.form.get('multiplicity').get("min")).setValue(0); + (this.form.get('multiplicity').get("max")).setValue(0); + } + } + + addNewRule() { + let rule: Rule = new Rule(); + this.dataModel.visible.rules.push(rule); + (this.form.get("visible").get("rules")).push(rule.buildForm()); + } + + DeleteRule(index) { + this.dataModel.visible.rules.splice(index, 1); + (this.form.get("visible").get("rules")).removeAt(index); + } + + onchangeCombo() { + if (this.form.get("data")) this.form.removeControl("data"); + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/dataset-profile-form/form/form.component.html b/dmp-frontend/src/app/dataset-profile-form/form/form.component.html new file mode 100644 index 000000000..2741ea42b --- /dev/null +++ b/dmp-frontend/src/app/dataset-profile-form/form/form.component.html @@ -0,0 +1,73 @@ +
+
+
+
+
+ + +
+
+ Label is required. +
+
+
+
+ + + + + + + + + + +
+
+
\ No newline at end of file diff --git a/dmp-frontend/src/app/dataset-profile-form/form/form.component.ts b/dmp-frontend/src/app/dataset-profile-form/form/form.component.ts new file mode 100644 index 000000000..b46186c0c --- /dev/null +++ b/dmp-frontend/src/app/dataset-profile-form/form/form.component.ts @@ -0,0 +1,89 @@ +import { JsonSerializer } from '../../utilities/JsonSerializer'; +import { DatasetProfileService } from '../../services/dataset-profile.service'; +import { DatasetProfileModelAdmin } from '../../models/datasetProfileAdmin/DatasetProfileModelAdmin'; +import { Page } from '../../models/datasetProfileAdmin/Page'; +import { Component, OnInit } from '@angular/core'; +import { FormGroup, FormControl } from '@angular/forms'; +import { SectionFormComponent } from '../section-form/section-form.component'; +import { FormArray } from '@angular/forms'; +import { Router, ActivatedRoute, ParamMap, Params } from '@angular/router'; +import { PageFormComponent } from '../page-form/page-component' +import { DatasetProfileAdmin } from '@app/services/datasetProfileAdmin/datasetProfileAfmin.service'; +import { Section } from '@app/models/datasetProfileAdmin/Section'; + +@Component({ + selector: 'form-comp', + templateUrl: './form.component.html', + providers:[DatasetProfileAdmin, DatasetProfileService], + styleUrls: [] +}) + +export class FormComponent { + + dataModel: DatasetProfileModelAdmin; + form: FormGroup; + private profileID: string; + + constructor(public datasetprofileAdmin: DatasetProfileAdmin, private datasetProfileService: DatasetProfileService, private route: ActivatedRoute) { + this.profileID = route.snapshot.params['id']; + } + + ngOnInit() { + + this.dataModel = JsonSerializer.fromJSONObject(new DatasetProfileModelAdmin(), DatasetProfileModelAdmin); + this.form = this.dataModel.buildForm(); + if (this.profileID) { + this.datasetProfileService.getDatasetProfileById(this.profileID).subscribe((data) => { + this.dataModel = JsonSerializer.fromJSONObject(data, DatasetProfileModelAdmin); + this.form = this.dataModel.buildForm(); + }); + } + else { + this.addSection(); + this.addPage(0); + } + } + + onIsMultiplicityEnabledChange(isMultiplicityEnabled: boolean) { + if (!isMultiplicityEnabled) { + (this.form.get('multiplicity').get("min")).setValue(0); + (this.form.get('multiplicity').get("max")).setValue(0); + } + } + + addSection() { + let section: Section = new Section(); + this.dataModel.sections.push(section); + (this.form.get("sections")).push(section.buildForm()); + } + + addPage(number) { + let page: Page = new Page(this.dataModel.pages.length); + this.dataModel.pages.push(page); + (this.form.get("pages")).push(page.buildForm()); + } + + DeleteSection(index) { + this.dataModel.sections.splice(index, 1); + (this.form.get("sections")).removeAt(index) + } + + DeletePage(index) { + this.dataModel.pages.splice(index, 1); + (this.form.get("pages")).removeAt(index) + } + + createForm(data) { + return this.datasetprofileAdmin.createForm(data); + } + updateForm(id, data) { + return this.datasetprofileAdmin.updateForm(id, data); + } + onSubmit() { + let data = this.form.value; + + if (this.profileID) this.updateForm(this.profileID, data).subscribe(); + else this.createForm(data).subscribe(); + } + +} \ No newline at end of file diff --git a/dmp-frontend/src/app/dataset-profile-form/page-form/page-component.html b/dmp-frontend/src/app/dataset-profile-form/page-form/page-component.html new file mode 100644 index 000000000..3ad68805d --- /dev/null +++ b/dmp-frontend/src/app/dataset-profile-form/page-form/page-component.html @@ -0,0 +1,8 @@ +
+
+
+ + +
+
+
\ No newline at end of file diff --git a/dmp-frontend/src/app/dataset-profile-form/page-form/page-component.ts b/dmp-frontend/src/app/dataset-profile-form/page-form/page-component.ts new file mode 100644 index 000000000..573ca355b --- /dev/null +++ b/dmp-frontend/src/app/dataset-profile-form/page-form/page-component.ts @@ -0,0 +1,19 @@ +import { Component, Input, Output, EventEmitter } from '@angular/core'; +import { FormGroup } from '@angular/forms' +import { Page } from '@app/models/datasetProfileAdmin/Page'; + + +@Component({ + selector: 'page-form', + templateUrl: './page-component.html', + styleUrls: [] +}) + +export class PageFormComponent { + @Input() form: FormGroup; + @Input() dataModel: Page; + + TargetValidation() { + } + +} \ No newline at end of file diff --git a/dmp-frontend/src/app/dataset-profile-form/rule-component/rule.component.html b/dmp-frontend/src/app/dataset-profile-form/rule-component/rule.component.html new file mode 100644 index 000000000..7ddb10c84 --- /dev/null +++ b/dmp-frontend/src/app/dataset-profile-form/rule-component/rule.component.html @@ -0,0 +1,33 @@ +
+
+
+
+ + +
+
+ + +
+ + +
+ + +
+
+
+
\ No newline at end of file diff --git a/dmp-frontend/src/app/dataset-profile-form/rule-component/rule.component.ts b/dmp-frontend/src/app/dataset-profile-form/rule-component/rule.component.ts new file mode 100644 index 000000000..fa91de7e3 --- /dev/null +++ b/dmp-frontend/src/app/dataset-profile-form/rule-component/rule.component.ts @@ -0,0 +1,18 @@ +import { Component, Input, Output, EventEmitter } from '@angular/core'; +import { FormGroup } from '@angular/forms' +import { Rule } from 'app/models/datasetProfileAdmin/Rule' + +@Component({ + selector: 'rule-form', + templateUrl: './rule.component.html', + styleUrls: [] +}) + +export class RuleFormComponent { +@Input() form: FormGroup; +@Input() dataModel: FormGroup; + +TargetValidation(){ +} + +} \ No newline at end of file diff --git a/dmp-frontend/src/app/dataset-profile-form/section-form/section-form.component.css b/dmp-frontend/src/app/dataset-profile-form/section-form/section-form.component.css new file mode 100644 index 000000000..1ded10469 --- /dev/null +++ b/dmp-frontend/src/app/dataset-profile-form/section-form/section-form.component.css @@ -0,0 +1,5 @@ +.section-container { + background-color: #f5f5f5; + border: 1px solid #e3e3e3; + padding: 24px; +} \ No newline at end of file diff --git a/dmp-frontend/src/app/dataset-profile-form/section-form/section-form.component.html b/dmp-frontend/src/app/dataset-profile-form/section-form/section-form.component.html new file mode 100644 index 000000000..1d3730e4f --- /dev/null +++ b/dmp-frontend/src/app/dataset-profile-form/section-form/section-form.component.html @@ -0,0 +1,124 @@ +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
Page is required
+
+
+ + + +
+
+
+ + + + + + + + + +
+
+
+ + {{i + 1}}. Field {{i + 1}} + +
+ +
+
+
+
+ +
+
+
+
+ + + + + +
\ No newline at end of file diff --git a/dmp-frontend/src/app/dataset-profile-form/section-form/section-form.component.ts b/dmp-frontend/src/app/dataset-profile-form/section-form/section-form.component.ts new file mode 100644 index 000000000..a7e2a4cef --- /dev/null +++ b/dmp-frontend/src/app/dataset-profile-form/section-form/section-form.component.ts @@ -0,0 +1,63 @@ +import { Component, OnInit, Input, ViewEncapsulation } from '@angular/core'; +import { FormGroup } from '@angular/forms'; +import { Section } from 'app/models/datasetProfileAdmin/Section'; +import { FormArray } from '@angular/forms'; +import { DatasetProfileModel } from 'app/models/DataSetProfile/DatasetProfileModel'; +import { FieldSet } from 'app/models/datasetProfileAdmin/FieldSet'; +import { Field } from 'app/models/datasetProfileAdmin/Field'; +import { Page } from 'app/models/datasetProfileAdmin/Page'; +import { JsonSerializer } from 'app/utilities/JsonSerializer'; + +@Component({ + selector: 'section-form', + templateUrl: './section-form.component.html', + styleUrls: ['./section-form.component.css'], + encapsulation: ViewEncapsulation.None +}) + +export class SectionFormComponent { + @Input() form: FormGroup; + @Input() dataModel: Section; + @Input() indexPath: string; + + constructor() { } + + ngOnInit() { + var self = this; + this.form.root.get("pages").valueChanges.subscribe(function (value) { + self.keepPageSelectionValid(value); + }); + } + + addField() { + let fieldSet: FieldSet = new FieldSet(); + let field: Field = new Field(); + fieldSet.fields.push(field); + if (this.dataModel.fieldSets) + this.dataModel.fieldSets.push(fieldSet); + (this.form.get("fieldSets")).push(fieldSet.buildForm()); + } + + addSectioninSection() { + let section: Section = new Section(); + this.dataModel.sections.push(section); + (this.form.get("sections")).push(section.buildForm()); + } + + DeleteSectionInSection(index) { + this.dataModel.sections.splice(index); + (this.form.get("sections")).removeAt(index); + } + + DeleteFieldSet(index) { + this.dataModel.fieldSets.splice(index, 1); + (this.form.get("fieldSets")).removeAt(index); + } + + keepPageSelectionValid(pagesJson: Array) { + let selectedPage = this.form.get("page").value as String; + let pages: Array = JsonSerializer.fromJSONArray(pagesJson, Page); + if (pages.find(elem => elem.id === selectedPage) === undefined) + this.form.get("page").reset(); + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/models/DataField/AutocompleteData.ts b/dmp-frontend/src/app/models/DataField/AutocompleteData.ts new file mode 100644 index 000000000..11873a833 --- /dev/null +++ b/dmp-frontend/src/app/models/DataField/AutocompleteData.ts @@ -0,0 +1,23 @@ +import { DataField } from './DataField'; +import { FormGroup } from '@angular/forms' + +export class AutocompleteData extends DataField{ + + public type:string; + public url:string; + + buildForm():FormGroup{ + return this.formBuilder.group({ + label:[this.label], + type:[this.type], + url:[this.url] + }) + } + + fromJSONObject(item:any):AutocompleteData{ + this.type = item.type; + this.url = item.url; + this.label = item.label; + return this; + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/models/DataField/BooleanDecisionData.ts b/dmp-frontend/src/app/models/DataField/BooleanDecisionData.ts new file mode 100644 index 000000000..f8d8c9dd6 --- /dev/null +++ b/dmp-frontend/src/app/models/DataField/BooleanDecisionData.ts @@ -0,0 +1,16 @@ +import { DataField } from './DataField'; +import { FormGroup } from '@angular/forms'; +export class BooleanDecisionData extends DataField{ + + buildForm():FormGroup{ + let formGroup = this.formBuilder.group({ + label:this.label + }); + return formGroup; + } + + fromJSONObject(item:any):BooleanDecisionData{ + this.label = item.label + return this; + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/models/DataField/CheckBoxData.ts b/dmp-frontend/src/app/models/DataField/CheckBoxData.ts new file mode 100644 index 000000000..ab3713697 --- /dev/null +++ b/dmp-frontend/src/app/models/DataField/CheckBoxData.ts @@ -0,0 +1,16 @@ +import { DataField } from './DataField'; +import { FormGroup } from '@angular/forms'; +export class CheckBoxData extends DataField{ + + buildForm():FormGroup{ + let formGroup = this.formBuilder.group({ + label:this.label + }); + return formGroup; + } + + fromJSONObject(item:any):CheckBoxData{ + this.label = item.label + return this; + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/models/DataField/DataField.ts b/dmp-frontend/src/app/models/DataField/DataField.ts new file mode 100644 index 000000000..e520408df --- /dev/null +++ b/dmp-frontend/src/app/models/DataField/DataField.ts @@ -0,0 +1,16 @@ +import { BaseModel } from '../BaseModel'; +import { FormGenerator } from '../interfaces/FormGenerator'; +import { Serializable } from '../interfaces/Serializable'; +import { FormGroup } from '@angular/forms' +export abstract class DataField extends BaseModel implements Serializable,FormGenerator{ + public label:string; + + buildForm():FormGroup{ + throw new Error("Build Form Is not not correctly overriden"); + } + + fromJSONObject(item:any):T{ + throw new Error("From Json Object is not correctly overriden") + } + +} \ No newline at end of file diff --git a/dmp-frontend/src/app/models/DataField/FreeTextData.ts b/dmp-frontend/src/app/models/DataField/FreeTextData.ts new file mode 100644 index 000000000..f32703ec0 --- /dev/null +++ b/dmp-frontend/src/app/models/DataField/FreeTextData.ts @@ -0,0 +1,16 @@ +import { DataField } from './DataField'; +import { FormGroup } from '@angular/forms'; +export class FreeTextData extends DataField{ + + buildForm():FormGroup{ + let formGroup = this.formBuilder.group({ + label:this.label + }); + return formGroup; + } + + fromJSONObject(item:any):FreeTextData{ + this.label = item.label + return this; + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/models/DataField/RadioBoxData.ts b/dmp-frontend/src/app/models/DataField/RadioBoxData.ts new file mode 100644 index 000000000..443f61437 --- /dev/null +++ b/dmp-frontend/src/app/models/DataField/RadioBoxData.ts @@ -0,0 +1,29 @@ +import { JsonSerializer } from '../../utilities/JsonSerializer'; +import { DataField } from './DataField'; +import { ListingItem } from '../Common/ListingItem'; +import { FormGroup } from '@angular/forms' + +export class RadioBoxData extends DataField{ + public options:Array; + + buildForm():FormGroup{ + let formGroup = this.formBuilder.group({ + label:[this.label] + }); + let optionsFormArray = new Array(); + if (this.options) { + this.options.forEach(item => { + let form: FormGroup = item.buildForm(); + optionsFormArray.push(form) + }) + } + formGroup.addControl('options', this.formBuilder.array(optionsFormArray)); + return formGroup; + } + + fromJSONObject(item:any):RadioBoxData{ + this.options = JsonSerializer.fromJSONArray(item.options,ListingItem); + this.label = item.label + return this; + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/models/DataField/TextArea.ts b/dmp-frontend/src/app/models/DataField/TextArea.ts new file mode 100644 index 000000000..f5e24dbcc --- /dev/null +++ b/dmp-frontend/src/app/models/DataField/TextArea.ts @@ -0,0 +1,16 @@ +import { DataField } from './DataField'; +import { FormGroup } from '@angular/forms'; +export class TextArea extends DataField