rsanchez
2017-03-20 1a0491f2462d2c309bd8e310b22c11019a79ce1e
#3527 fix - Added applications forms and metadata component
1 files deleted
25 files modified
changed files
securis/src/main/java/net/curisit/securis/DevFilter.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/ApplicationMetadata.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/LicenseTypeMetadata.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/PackMetadata.java patch | view | blame | history
securis/src/main/webapp/src/app/app.module.ts patch | view | blame | history
securis/src/main/webapp/src/app/common/error.checker.ts patch | view | blame | history
securis/src/main/webapp/src/app/common/i18n.ts patch | view | blame | history
securis/src/main/webapp/src/app/common/utils.ts patch | view | blame | history
securis/src/main/webapp/src/app/forms/application.form.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/forms/application.form.html patch | view | blame | history
securis/src/main/webapp/src/app/forms/base.ts patch | view | blame | history
securis/src/main/webapp/src/app/forms/license.form.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/forms/license.form.html patch | view | blame | history
securis/src/main/webapp/src/app/forms/pack.form.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/forms/pack.form.html patch | view | blame | history
securis/src/main/webapp/src/app/listing/application.list.component.html patch | view | blame | history
securis/src/main/webapp/src/app/listing/pack.list.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/applications.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/base.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/license_types.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/licenses.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/organizations.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/packs.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/users.ts patch | view | blame | history
securis/src/main/webapp/src/app/user.service.ts patch | view | blame | history
securis/src/main/webapp/src/lang/messages_en.json patch | view | blame | history
securis/src/main/java/net/curisit/securis/DevFilter.java
....@@ -33,7 +33,7 @@
3333 // For dev. using JS in different server
3434 res.addHeader("Access-Control-Allow-Origin", "*");
3535 //res.addHeader("Access-Control-Request-Headers", "*");
36
- res.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, OPTIONS");
36
+ res.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
3737 res.addHeader("Access-Control-Allow-Headers", "X-SECURIS-TOKEN, Content-Type");
3838 res.addHeader("Access-Control-Expose-Headers", "X-SECURIS-ERROR-MSG, X-SECURIS-ERROR-CODE, Content-Type");
3939
securis/src/main/java/net/curisit/securis/db/ApplicationMetadata.java
....@@ -17,6 +17,7 @@
1717
1818 import com.fasterxml.jackson.annotation.JsonAutoDetect;
1919 import com.fasterxml.jackson.annotation.JsonBackReference;
20
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
2021 import com.fasterxml.jackson.annotation.JsonInclude;
2122 import com.fasterxml.jackson.annotation.JsonInclude.Include;
2223 import com.fasterxml.jackson.annotation.JsonProperty;
....@@ -29,78 +30,77 @@
2930 @JsonInclude(Include.NON_NULL)
3031 @Entity
3132 @Table(name = "application_metadata")
32
-@NamedQueries({
33
- @NamedQuery(name = "list-application-metadata", query = "SELECT a FROM ApplicationMetadata a where a.application.id = :applicationId")
34
-})
33
+@JsonIgnoreProperties(value = { "readonly" })
34
+@NamedQueries({ @NamedQuery(name = "list-application-metadata", query = "SELECT a FROM ApplicationMetadata a where a.application.id = :applicationId") })
3535 public class ApplicationMetadata implements Serializable {
3636
37
- private static final Logger LOG = LogManager.getLogger(ApplicationMetadata.class);
37
+ private static final Logger LOG = LogManager.getLogger(ApplicationMetadata.class);
3838
39
- private static final long serialVersionUID = 1L;
39
+ private static final long serialVersionUID = 1L;
4040
41
- @Id
42
- @ManyToOne
43
- @JoinColumn(name = "application_id")
44
- @JsonBackReference
45
- private Application application;
41
+ @Id
42
+ @ManyToOne
43
+ @JoinColumn(name = "application_id")
44
+ @JsonBackReference
45
+ private Application application;
4646
47
- @Id
48
- @Column(name = "\"key\"")
49
- private String key;
47
+ @Id
48
+ @Column(name = "\"key\"")
49
+ private String key;
5050
51
- private String value;
51
+ private String value;
5252
53
- private boolean mandatory;
53
+ private boolean mandatory;
5454
55
- @Column(name = "creation_timestamp")
56
- @JsonProperty("creation_timestamp")
57
- private Date creationTimestamp;
55
+ @Column(name = "creation_timestamp")
56
+ @JsonProperty("creation_timestamp")
57
+ private Date creationTimestamp;
5858
59
- public String getKey() {
60
- return key;
61
- }
59
+ public String getKey() {
60
+ return key;
61
+ }
6262
63
- public void setKey(String key) {
64
- this.key = key;
65
- }
63
+ public void setKey(String key) {
64
+ this.key = key;
65
+ }
6666
67
- public Application getApplication() {
68
- LOG.info("Getting application from app metadata: {}", application);
69
- return application;
70
- }
67
+ public Application getApplication() {
68
+ LOG.info("Getting application from app metadata: {}", application);
69
+ return application;
70
+ }
7171
72
- public void setApplication(Application application) {
73
- this.application = application;
74
- }
72
+ public void setApplication(Application application) {
73
+ this.application = application;
74
+ }
7575
76
- public Date getCreationTimestamp() {
77
- return creationTimestamp;
78
- }
76
+ public Date getCreationTimestamp() {
77
+ return creationTimestamp;
78
+ }
7979
80
- public void setCreationTimestamp(Date creationTimestamp) {
81
- this.creationTimestamp = creationTimestamp;
82
- }
80
+ public void setCreationTimestamp(Date creationTimestamp) {
81
+ this.creationTimestamp = creationTimestamp;
82
+ }
8383
84
- public String getValue() {
85
- return value;
86
- }
84
+ public String getValue() {
85
+ return value;
86
+ }
8787
88
- public void setValue(String value) {
89
- this.value = value;
90
- }
88
+ public void setValue(String value) {
89
+ this.value = value;
90
+ }
9191
92
- public boolean isMandatory() {
93
- return mandatory;
94
- }
92
+ public boolean isMandatory() {
93
+ return mandatory;
94
+ }
9595
96
- public void setMandatory(boolean mandatory) {
97
- this.mandatory = mandatory;
98
- }
96
+ public void setMandatory(boolean mandatory) {
97
+ this.mandatory = mandatory;
98
+ }
9999
100
- @Override
101
- public String toString() {
100
+ @Override
101
+ public String toString() {
102102
103
- return String.format("ApplicationMetadata (%s)", this.key);
104
- }
103
+ return String.format("ApplicationMetadata (%s)", this.key);
104
+ }
105105
106106 }
securis/src/main/java/net/curisit/securis/db/LicenseTypeMetadata.java
....@@ -13,6 +13,7 @@
1313
1414 import com.fasterxml.jackson.annotation.JsonAutoDetect;
1515 import com.fasterxml.jackson.annotation.JsonBackReference;
16
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
1617 import com.fasterxml.jackson.annotation.JsonInclude;
1718 import com.fasterxml.jackson.annotation.JsonInclude.Include;
1819
....@@ -24,56 +25,55 @@
2425 @JsonInclude(Include.NON_NULL)
2526 @Entity
2627 @Table(name = "licensetype_metadata")
27
-@NamedQueries({
28
- @NamedQuery(name = "list-licensetype-metadata", query = "SELECT a FROM LicenseTypeMetadata a where a.licenseType.id = :licenseTypeId")
29
-})
28
+@JsonIgnoreProperties(value = { "readonly" })
29
+@NamedQueries({ @NamedQuery(name = "list-licensetype-metadata", query = "SELECT a FROM LicenseTypeMetadata a where a.licenseType.id = :licenseTypeId") })
3030 public class LicenseTypeMetadata implements Serializable {
3131
32
- private static final long serialVersionUID = 1L;
32
+ private static final long serialVersionUID = 1L;
3333
34
- @Id
35
- @ManyToOne
36
- @JsonBackReference
37
- @JoinColumn(name = "license_type_id")
38
- private LicenseType licenseType;
34
+ @Id
35
+ @ManyToOne
36
+ @JsonBackReference
37
+ @JoinColumn(name = "license_type_id")
38
+ private LicenseType licenseType;
3939
40
- @Id
41
- @Column(name = "\"key\"")
42
- private String key;
40
+ @Id
41
+ @Column(name = "\"key\"")
42
+ private String key;
4343
44
- private String value;
44
+ private String value;
4545
46
- private boolean mandatory;
46
+ private boolean mandatory;
4747
48
- public LicenseType getLicenseType() {
49
- return licenseType;
50
- }
48
+ public LicenseType getLicenseType() {
49
+ return licenseType;
50
+ }
5151
52
- public void setLicenseType(LicenseType licenseType) {
53
- this.licenseType = licenseType;
54
- }
52
+ public void setLicenseType(LicenseType licenseType) {
53
+ this.licenseType = licenseType;
54
+ }
5555
56
- public String getValue() {
57
- return value;
58
- }
56
+ public String getValue() {
57
+ return value;
58
+ }
5959
60
- public void setValue(String value) {
61
- this.value = value;
62
- }
60
+ public void setValue(String value) {
61
+ this.value = value;
62
+ }
6363
64
- public String getKey() {
65
- return key;
66
- }
64
+ public String getKey() {
65
+ return key;
66
+ }
6767
68
- public void setKey(String key) {
69
- this.key = key;
70
- }
68
+ public void setKey(String key) {
69
+ this.key = key;
70
+ }
7171
72
- public boolean isMandatory() {
73
- return mandatory;
74
- }
72
+ public boolean isMandatory() {
73
+ return mandatory;
74
+ }
7575
76
- public void setMandatory(boolean mandatory) {
77
- this.mandatory = mandatory;
78
- }
76
+ public void setMandatory(boolean mandatory) {
77
+ this.mandatory = mandatory;
78
+ }
7979 }
securis/src/main/java/net/curisit/securis/db/PackMetadata.java
....@@ -13,6 +13,7 @@
1313
1414 import com.fasterxml.jackson.annotation.JsonAutoDetect;
1515 import com.fasterxml.jackson.annotation.JsonIgnore;
16
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
1617 import com.fasterxml.jackson.annotation.JsonInclude;
1718 import com.fasterxml.jackson.annotation.JsonInclude.Include;
1819 import com.fasterxml.jackson.annotation.JsonProperty;
....@@ -25,82 +26,81 @@
2526 @JsonInclude(Include.NON_NULL)
2627 @Entity
2728 @Table(name = "pack_metadata")
28
-@NamedQueries({
29
- @NamedQuery(name = "list-pack-metadata", query = "SELECT a FROM PackMetadata a where a.pack.id = :packId")
30
-})
29
+@JsonIgnoreProperties(value = { "readonly" })
30
+@NamedQueries({ @NamedQuery(name = "list-pack-metadata", query = "SELECT a FROM PackMetadata a where a.pack.id = :packId") })
3131 public class PackMetadata implements Serializable {
3232
33
- private static final long serialVersionUID = 1L;
33
+ private static final long serialVersionUID = 1L;
3434
35
- @Id
36
- @JsonIgnore
37
- @ManyToOne
38
- @JoinColumn(name = "pack_id")
39
- private Pack pack;
35
+ @Id
36
+ @JsonIgnore
37
+ @ManyToOne
38
+ @JoinColumn(name = "pack_id")
39
+ private Pack pack;
4040
41
- @Id
42
- @Column(name = "\"key\"")
43
- private String key;
41
+ @Id
42
+ @Column(name = "\"key\"")
43
+ private String key;
4444
45
- private String value;
45
+ private String value;
4646
47
- private boolean readonly;
47
+ private boolean readonly;
4848
49
- private boolean mandatory;
49
+ private boolean mandatory;
5050
51
- @JsonProperty("pack_id")
52
- public Integer getPackId() {
53
- return pack == null ? null : pack.getId();
54
- }
51
+ @JsonProperty("pack_id")
52
+ public Integer getPackId() {
53
+ return pack == null ? null : pack.getId();
54
+ }
5555
56
- @JsonProperty("pack_id")
57
- public void setLicenseTypeId(Integer idPack) {
58
- if (idPack == null) {
59
- pack = null;
60
- } else {
61
- pack = new Pack();
62
- pack.setId(idPack);
63
- }
64
- }
56
+ @JsonProperty("pack_id")
57
+ public void setLicenseTypeId(Integer idPack) {
58
+ if (idPack == null) {
59
+ pack = null;
60
+ } else {
61
+ pack = new Pack();
62
+ pack.setId(idPack);
63
+ }
64
+ }
6565
66
- public Pack getPack() {
67
- return pack;
68
- }
66
+ public Pack getPack() {
67
+ return pack;
68
+ }
6969
70
- public void setPack(Pack pack) {
71
- this.pack = pack;
72
- }
70
+ public void setPack(Pack pack) {
71
+ this.pack = pack;
72
+ }
7373
74
- public String getValue() {
75
- return value;
76
- }
74
+ public String getValue() {
75
+ return value;
76
+ }
7777
78
- public void setValue(String value) {
79
- this.value = value;
80
- }
78
+ public void setValue(String value) {
79
+ this.value = value;
80
+ }
8181
82
- public String getKey() {
83
- return key;
84
- }
82
+ public String getKey() {
83
+ return key;
84
+ }
8585
86
- public void setKey(String key) {
87
- this.key = key;
88
- }
86
+ public void setKey(String key) {
87
+ this.key = key;
88
+ }
8989
90
- public boolean isReadonly() {
91
- return readonly;
92
- }
90
+ public boolean isReadonly() {
91
+ return readonly;
92
+ }
9393
94
- public void setReadonly(boolean readonly) {
95
- this.readonly = readonly;
96
- }
94
+ public void setReadonly(boolean readonly) {
95
+ this.readonly = readonly;
96
+ }
9797
98
- public boolean isMandatory() {
99
- return mandatory;
100
- }
98
+ public boolean isMandatory() {
99
+ return mandatory;
100
+ }
101101
102
- public void setMandatory(boolean mandatory) {
103
- this.mandatory = mandatory;
104
- }
102
+ public void setMandatory(boolean mandatory) {
103
+ this.mandatory = mandatory;
104
+ }
105105
106106 }
securis/src/main/webapp/src/app/app.module.ts
....@@ -1,4 +1,3 @@
1
-import { ErrorCheckerComponent } from './common/error.checker';
21 import { NgModule } from '@angular/core';
32 import { BrowserModule } from '@angular/platform-browser';
43 import { CommonModule } from '@angular/common';
....@@ -13,6 +12,10 @@
1312
1413 import { HomeComponent } from './home.component';
1514 import { I18nDirective } from './common/i18n';
15
+import { MetadataManagerComponent } from './forms/base';
16
+import { FieldReadonlyComponent } from './forms/base';
17
+import { ErrorCheckerComponent } from './forms/base';
18
+
1619 import { UserService } from './user.service';
1720 import { PacksService } from './resources/packs';
1821 import { LicenseTypesService } from './resources/license_types';
....@@ -23,7 +26,6 @@
2326 import { MenuComponent } from './menu.component';
2427 import { NoMenuComponent } from './nomenu.component';
2528 import { FooterComponent } from './footer.component';
26
-import { FieldReadonlyComponent } from './common/utils';
2729 import { LicenseListComponent } from './listing/license.list.component';
2830 import { PackListComponent } from './listing/pack.list.component';
2931 import { LoginFormComponent } from './forms/login.form.component';
....@@ -68,7 +70,8 @@
6870 MenuComponent,
6971 NoMenuComponent,
7072 FieldReadonlyComponent,
71
- FooterComponent
73
+ FooterComponent,
74
+ MetadataManagerComponent
7275 ],
7376 bootstrap: [ HomeComponent ],
7477 entryComponents: [ ],
securis/src/main/webapp/src/app/common/error.checker.ts
deleted file mode 100644
....@@ -1,54 +0,0 @@
1
-import { Http } from '@angular/http';
2
-import { PacksService } from '../resources/packs';
3
-import { LocaleService } from '../common/i18n';
4
-import { TdDataTableService, TdDataTableSortingOrder, ITdDataTableSortChangeEvent, ITdDataTableColumn } from '@covalent/core';
5
-import { IPageChangeEvent } from '@covalent/core';
6
-import { Component, Input, AfterViewInit } from '@angular/core';
7
-import { TdMediaService } from '@covalent/core';
8
-
9
-@Component({
10
- selector: 'error-checker',
11
- template: `
12
- <div *ngIf="formField?.touched && formField.invalid" layout="column">
13
- <span *ngFor="let err of getFieldErrors()" align="end">{{err}}</span>
14
- </div>`
15
-})
16
-export class ErrorCheckerComponent {
17
-
18
- @Input() formField: any;
19
- @Input() fieldName: string;
20
-
21
- constructor(private $L: LocaleService) {
22
- }
23
-
24
- getFieldErrors() : string[] {
25
- if (this.formField.valid) {
26
- return []
27
- } else {
28
- return (<string[]>Object.keys(this.formField.errors)).map((err:string) => this.getErrorMsg(err));
29
- }
30
- }
31
-
32
- private updateFieldErrors() {
33
- }
34
-
35
- private getErrorMsg(err: string) : string{
36
- switch(err) {
37
- case 'required': {
38
- return this.fieldName + ' '+ this.$L.get('is required');
39
- }
40
- case 'number': {
41
- return this.fieldName + ' '+ this.$L.get('should be a number');
42
- }
43
- default: {
44
- return this.fieldName + ' '+ this.$L.get('unknown error') + ' ' + err;
45
- }
46
- }
47
- }
48
-
49
- log(obj: any) {
50
- console.log(obj)
51
- }
52
-
53
-}
54
-
securis/src/main/webapp/src/app/common/i18n.ts
....@@ -93,7 +93,7 @@
9393 * $L.get('hello'); // This returns "hola"
9494 * $L.get('Hello {0}!!', 'John'); // This returns: "Hola John!!" if language is spanish
9595 */
96
- get(msg: string, ...params: string[] ) : string {
96
+ get(msg: string, ...params: any[] ) : string {
9797 if (msg == null) {
9898 return '';
9999 }
securis/src/main/webapp/src/app/common/utils.ts
....@@ -1,50 +1,65 @@
11
2
-import {Component, Input} from '@angular/core';
2
+import { Component, Injectable, Input } from '@angular/core';
33 import {LocaleService} from './i18n';
4
+import { Observable } from 'rxjs/Observable';
45
5
-@Component({
6
- selector: 'field-readonly',
7
- template: `
8
- <div layout="column" class="mat-input-container readonly" >
9
- <div class="mat-input-wrapper">
10
- <div class="mat-input-table">
11
- <div class="mat-input-prefix"></div>
12
- <div class="mat-input-infix">
13
- <div class="label-value mat-input-element">{{value}}</div>
14
- <span class="mat-input-placeholder-wrapper" >
15
- <label class="mat-input-placeholder mat-float">
16
- <span class="placeholder">{{label}}</span>
17
- </label>
18
- </span>
19
- </div>
20
- <div class="mat-input-suffix"></div>
21
- </div>
22
- <div class="mat-input-underline"></div>
23
- </div>
24
- </div>`,
25
- styles: [`.readonly .mat-input-element {
26
- margin-top: 0px !important;
27
- color: rgba(0, 0, 0, 0.50);
28
- }`,
29
- `.readonly .mat-input-element {
30
- margin-top: 0px;
31
- color: rgba(0, 0, 0, 0.50);
32
- }`,
33
- `.readonly.mat-input-container {
34
- width: 100%;
35
- }`]
36
-})
37
-export class FieldReadonlyComponent {
38
- @Input('value') value: any;
396
40
- private _label : string;
41
- @Input('label')
42
- set label(txt: string) {
43
- this._label = this.$L.get(txt);
44
- }
45
- get label(): string { return this._label; }
467
47
- constructor(private $L : LocaleService) {
8
+export interface IError {
9
+ code: string | number,
10
+ message: string,
11
+ httpCode?: number
12
+}
4813
49
- }
14
+export const DEFAULT_APP_ERROR_STATUS_CODE = 418;
15
+export const ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR-MSG";
16
+export const ERROR_CODE_MESSAGE_HEADER = "X-SECURIS-ERROR-CODE";
17
+
18
+export class ErrorCodes {
19
+ public static UNEXPECTED_ERROR = 1000;
20
+ public static INVALID_CREDENTIALS = 1001;
21
+ public static UNAUTHORIZED_ACCESS = 1002;
22
+ public static NOT_FOUND = 1003;
23
+ public static INVALID_FORMAT = 1004;
24
+ public static WRONG_STATUS = 1005;
25
+
26
+ public static INVALID_LICENSE_REQUEST_DATA = 1100;
27
+ public static LICENSE_NOT_READY_FOR_RENEW = 1101;
28
+ public static LICENSE_DATA_IS_NOT_VALID = 1102;
29
+ public static LICENSE_IS_EXPIRED = 1103;
30
+
31
+ public static INVALID_REQUEST_DATA = 1201;
32
+ public static INVALID_REQUEST_DATA_FORMAT = 1202;
33
+ public static BLOCKED_REQUEST_DATA = 1203;
34
+ public static DUPLICATED_REQUEST_DATA = 1204;
35
+ public static NO_AVAILABLE_LICENSES = 1205;
36
+
37
+ public static INVALID_DATA = 1301;
38
+}
39
+
40
+@Injectable()
41
+export class BasicService {
42
+
43
+ constructor(protected $L: LocaleService) {}
44
+
45
+ public processErrorResponse(errorResponse: Response | any) {
46
+ // In a real world app, we might use a remote logging infrastructure
47
+ var error: IError = <IError>{};
48
+ if (errorResponse instanceof Response) {
49
+ error.httpCode = errorResponse.status;
50
+ }
51
+
52
+ error.code = errorResponse.headers.get(ERROR_CODE_MESSAGE_HEADER) || error.httpCode;
53
+
54
+ if (errorResponse.status === 403 /* forbidden */ || errorResponse.status === 401 /* unauthorized */) {
55
+ error.message = this.$L.get('Invalid credentials');
56
+ error.code = ErrorCodes.INVALID_CREDENTIALS;
57
+ } else if (errorResponse.status === 418 /* Teapot */) {
58
+ error.message = errorResponse.headers.get(ERROR_MESSAGE_HEADER) || errorResponse.statusText || this.$L.get('Unknown');
59
+ } else {
60
+ error.message = this.$L.get(`Unexpected error HTTP (${error.httpCode}) accessing to server. Contact with the administrator.`);
61
+ }
62
+
63
+ return Observable.throw(error);
64
+ }
5065 }
securis/src/main/webapp/src/app/forms/application.form.component.ts
....@@ -4,7 +4,7 @@
44 import { ApplicationsService } from '../resources/applications';
55 import { LicenseTypesService } from '../resources/license_types';
66 import { LocaleService } from '../common/i18n';
7
-import { IPageChangeEvent } from '@covalent/core';
7
+import { TdDialogService } from '@covalent/core';
88 import { Component, AfterViewInit } from '@angular/core';
99 import { TdMediaService } from '@covalent/core';
1010 import { FormBase, IComboOption } from './base';
....@@ -30,25 +30,15 @@
3030 })
3131 export class ApplicationFormComponent extends FormBase {
3232
33
- fields: any = {
34
- 'id': '',
35
- 'code': '',
36
- 'name': '',
37
- 'creation_timestamp': '',
38
- 'license_filename': '',
39
- 'description': '',
40
- 'metadata': '',
41
- 'key': '',
42
- 'value': '',
43
- }
4433 constructor(private http: Http,
4534 private licenseTypes: LicenseTypesService,
4635 private router: Router,
4736 private applications: ApplicationsService,
4837 toaster: ToastsManager,
4938 route: ActivatedRoute,
50
- $L: LocaleService) {
51
- super($L, route, toaster, applications, $L.get('application'));
39
+ $L: LocaleService,
40
+ dialogs: TdDialogService) {
41
+ super($L, route, toaster, applications, $L.get('application'), dialogs);
5242 }
5343
5444
....@@ -58,7 +48,9 @@
5848
5949
6050 ngAfterViewInit(): void {
61
- super.prepareData('applicationId');
51
+ super.prepareInitialData('applicationId', {
52
+ metadata: []
53
+ });
6254 }
6355 }
6456
securis/src/main/webapp/src/app/forms/application.form.html
....@@ -7,6 +7,20 @@
77 <span flex></span>
88 <button md-icon-button (click)="save()"><md-icon>save</md-icon></button>
99 </md-toolbar>
10
+ <!--
11
+ code: 'CICS',
12
+ creation_timestamp: 1418384439000,
13
+ description: 'Wellbore integrity analysis software',
14
+ id: 1,
15
+ license_filename: 'config_server.lic',
16
+ name: 'CurisIntegrity',
17
+ metadata:
18
+ [ { key: 'max_docs',
19
+ value: '250000',
20
+ readonly: true,
21
+ mandatory: true } ]
22
+}
23
+ -->
1024 <div class="margin" layout-align-gt-xs="center start" layout-fill="" layout-gt-xs="row">
1125 <md-card flex="70">
1226 <md-card-title>
....@@ -27,121 +41,49 @@
2741 </md-input-container>
2842 <error-checker [fieldName]="getFieldName('code')" [formField]="applicationForm.controls.code"></error-checker>
2943 </div>
44
+ </div>
45
+ <div layout="row" layout-fill layout-padding>
3046 <div layout="column" layout-fill flex>
31
- <md-input-container>
32
- <input mdInput type="number" [(ngModel)]="data.num_licenses" name="num_licenses" required />
47
+ <md-input-container flex>
48
+ <input mdInput type="text" [(ngModel)]="data.name" name="name" required />
3349 <md-placeholder>
34
- <span i18n="field.num_licenses"></span>
50
+ <span i18n="field.name"></span>
3551 </md-placeholder>
3652 </md-input-container>
37
- <error-checker [fieldName]="getFieldName('num_licenses')" [formField]="applicationForm.controls.num_licenses"></error-checker>
53
+ <error-checker [fieldName]="getFieldName('name')" [formField]="applicationForm.controls.name"></error-checker>
54
+ </div>
55
+ <div layout="column" layout-fill flex>
56
+ <md-input-container flex>
57
+ <input mdInput type="text" [(ngModel)]="data.license_filename" name="license_filename" required />
58
+ <md-placeholder>
59
+ <span i18n="field.license_filename"></span>
60
+ </md-placeholder>
61
+ </md-input-container>
62
+ <error-checker [fieldName]="getFieldName('license_filename')" [formField]="applicationForm.controls.license_filename"></error-checker>
3863 </div>
3964 </div>
4065 <div layout="row" layout-fill layout-padding>
4166 <div layout="column" layout-fill flex>
4267 <md-input-container flex>
43
- <input mdInput type="date" [(ngModel)]="data.init_valid_date" name="init_valid_date" required />
68
+ <textarea mdInput type="text" type="text" [(ngModel)]="data.description" name="description" maxlength="1024"></textarea>
4469 <md-placeholder>
45
- <span i18n="field.end_valid_date"></span>
46
- </md-placeholder>
47
- </md-input-container>
48
- <error-checker [fieldName]="getFieldName('init_valid_date')" [formField]="applicationForm.controls.init_valid_date"></error-checker>
49
- </div>
50
- <div layout="column" layout-fill flex>
51
- <md-input-container flex>
52
- <input mdInput type="date" [(ngModel)]="data.end_valid_date" name="end_valid_date" required />
53
- <md-placeholder>
54
- <span i18n="field.end_valid_date"></span>
55
- </md-placeholder>
56
- </md-input-container>
57
- <error-checker [fieldName]="getFieldName('end_valid_date')" [formField]="applicationForm.controls.end_valid_date"></error-checker>
58
- </div>
59
- </div>
60
- <div layout="row" layout-fill layout-padding *ngIf="isNew">
61
- <div layout="column" layout-fill flex>
62
- <md-select [placeholder]="getFieldName('organization_id')" flex [(ngModel)]="data.organization_id" name="organization_id"
63
- (change)="changeOrg($event)">
64
- <md-option *ngFor="let org of organizations" [value]="org.id">
65
- {{org.label}}
66
- </md-option>
67
- </md-select>
68
- <error-checker [fieldName]="getFieldName('organization_id')" [formField]="applicationForm.controls.organization_id"></error-checker>
69
- </div>
70
- <div layout="column" layout-fill flex>
71
- <md-select flex [placeholder]="getFieldName('license_type_id')" [(ngModel)]="data.license_type_id" name="license_type_id"
72
- (change)="changeLicType($event)">
73
- <md-option *ngFor="let lt of licensetypes" [value]="lt.id">
74
- {{lt.label}}
75
- </md-option>
76
- </md-select>
77
- <error-checker [fieldName]="getFieldName('license_type_id')" [formField]="applicationForm.controls.license_type_id"></error-checker>
78
- </div>
79
- </div>
80
- <div layout="row" layout-fill layout-padding *ngIf="!isNew">
81
- <field-readonly [value]="data.organization_name" label="field.organization_id" flex></field-readonly>
82
- <field-readonly [value]="data.licensetype_code" label="field.license_type_id" flex></field-readonly>
83
- </div>
84
- <div layout="row" layout-fill layout-padding>
85
- <div layout="column" layout-fill flex>
86
- <md-input-container flex>
87
- <input mdInput type="number" [(ngModel)]="data.preactivation_valid_period" name="preactivation_valid_period" required />
88
- <md-placeholder>
89
- <span i18n="field.preactivation_valid_period"></span>
90
- </md-placeholder>
91
- <md-hint align="end">days</md-hint>
92
- </md-input-container>
93
- <error-checker [fieldName]="getFieldName('preactivation_valid_period')" [formField]="applicationForm.controls.preactivation_valid_period"></error-checker>
94
- </div>
95
- <div layout="column" layout-fill flex>
96
- <md-input-container flex>
97
- <input mdInput type="number" [(ngModel)]="data.renew_valid_period" name="renew_valid_period" required />
98
- <md-placeholder>
99
- <span i18n="field.renew_valid_period"></span>
100
- </md-placeholder>
101
- <md-hint align="end">days</md-hint>
102
- </md-input-container>
103
- <error-checker [fieldName]="getFieldName('renew_valid_period')" [formField]="applicationForm.controls.renew_valid_period"></error-checker>
104
- </div>
105
- </div>
106
- <div layout="row" layout-fill layout-padding>
107
- <div layout="column" layout-fill flex>
108
- <md-input-container flex>
109
- <textarea mdInput type="text" type="text" [(ngModel)]="data.comments" name="comments" maxlength="1024"></textarea>
110
- <md-placeholder>
111
- <span i18n="field.comments"></span>
70
+ <span i18n="field.description"></span>
11271 </md-placeholder>
11372 <md-hint align="end">(max 1024)</md-hint>
11473 </md-input-container>
11574 </div>
11675 </div>
11776 <div layout="row" layout-fill layout-padding *ngIf="!isNew">
118
- <field-readonly [value]="data.created_by_name" label="field.created_by" flex></field-readonly>
11977 <field-readonly [value]="data.creation_timestamp | date: 'medium'" label="field.creation_timestamp" flex></field-readonly>
12078 </div>
121
- <div layout="column" layout-fill>
122
- <span class="md-title" i18n>License metadata</span>
123
- <div layout="row" layout-fill layout-padding *ngFor="let pair of data.metadata">
124
- <md-input-container flex="40">
125
- <input mdInput type="text" [ngModelOptions]="{standalone: true}" [(ngModel)]="pair.key" readonly />
126
- <md-placeholder>
127
- <span i18n="field.key"></span>
128
- </md-placeholder>
129
- </md-input-container>
130
- <md-input-container flex>
131
- <input mdInput type="text" [ngModelOptions]="{standalone: true}" [(ngModel)]="pair.value" [readonly]="pair.readonly" [required]="pair.required"
132
- />
133
- <md-placeholder>
134
- <span i18n="field.value"></span>
135
- </md-placeholder>
136
- </md-input-container>
137
- </div>
138
- </div>
79
+ <metadata-manager addOrDelete="true" editKeys="true" [metadata]="data.metadata" ></metadata-manager>
13980 </div>
14081 </form>
14182 </md-card-content>
14283 <md-divider></md-divider>
14384 <md-card-actions>
14485 <div layout="row" layout-align="start center" class="margin">
86
+ <button *ngIf="!isNew" md-raised-button color="warn" (click)="delete(data.id)">Delete</button>
14587 <span flex></span>
14688 <button [disabled]="!applicationForm.form.valid" md-raised-button color="primary" (click)="save()">Save</button>
14789 <button md-button (click)="goBack()">Cancel</button>
securis/src/main/webapp/src/app/forms/base.ts
....@@ -1,11 +1,13 @@
11 import { Http } from '@angular/http';
22 import { ActivatedRoute } from '@angular/router';
3
+import { TdDialogService } from '@covalent/core';
34 import { ToastsManager } from 'ng2-toastr/ng2-toastr';
45
56 import { LocaleService } from '../common/i18n';
7
+import { BasicService } from '../common/utils';
68 import { SeCurisResourceServices } from '../resources/base';
79
8
-import { AfterViewInit } from '@angular/core';
10
+import { AfterViewInit, Component, Input } from '@angular/core';
911
1012
1113 export interface IComboOption {
....@@ -14,17 +16,19 @@
1416 }
1517
1618
17
-export class FormBase {
19
+export class FormBase extends BasicService {
1820 protected form_title: string = '';
1921 protected form_subtitle: string = '';
2022 protected data: any = {};
2123 protected isNew : boolean = true;
2224
23
- constructor(protected $L: LocaleService,
25
+ constructor($L: LocaleService,
2426 protected route: ActivatedRoute,
2527 protected toaster: ToastsManager,
2628 protected resourceServices: SeCurisResourceServices,
27
- protected resourceName: string ) {
29
+ protected resourceName: string,
30
+ protected dialogs : TdDialogService ) {
31
+ super($L);
2832 }
2933
3034 public getFieldName(fieldId: string) : string {
....@@ -36,15 +40,30 @@
3640 save() {
3741 var command = this.isNew ? this.resourceServices.create(this.data) : this.resourceServices.modify(this.data.id, this.data);
3842 command.subscribe(
39
- data => this.toaster.success(this.$L.get('{} saved sucessfully', this.$L.get(this.resourceName).capitalize())),
40
- err => {
41
- console.error(err);
42
- this.toaster.success(this.$L.get('Error saving {}', this.$L.get(this.resourceName)));
43
- }
44
- );
43
+ data => this.toaster.success(this.$L.get('{} saved sucessfully', this.resourceName.capitalize())),
44
+ err => this.toaster.error(err.message, this.$L.get('Error saving {}', this.resourceName))
45
+ );
4546 }
4647
47
- protected prepareData(idparam: string, default_values: any = {}) : void {
48
+ delete(eleId: number | string) : void {
49
+ this.dialogs.openConfirm({
50
+ message: this.$L.get('The {} with ID {} will be deleted. Do you want to continue ?', this.resourceName, eleId),
51
+ disableClose: false, // defaults to false
52
+ title: this.$L.get('Delete {}', this.resourceName),
53
+ cancelButton: this.$L.get('Cancel'),
54
+ acceptButton: this.$L.get('Yes, delete')
55
+ }).afterClosed().subscribe((accept: boolean) => {
56
+ if (accept) {
57
+ this.resourceServices.remove(eleId)
58
+ .subscribe(
59
+ responseData => this.toaster.success(this.$L.get('{} was sucessfully deleted', this.resourceName.capitalize())),
60
+ err => this.toaster.success(err.message, this.$L.get('Error deleting the {}', this.resourceName))
61
+ );
62
+ }
63
+ });
64
+ }
65
+
66
+ protected prepareInitialData(idparam: string, default_values: any = {}) : void {
4867 this.form_title = this.$L.get('{} data', this.resourceName.capitalize());
4968 this.isNew = true;
5069 !!this.route && this.route.params.subscribe(params => {
....@@ -61,4 +80,173 @@
6180 });
6281 }
6382
64
-}
83
+}
84
+
85
+@Component({
86
+ selector: 'error-checker',
87
+ template: `
88
+ <div *ngIf="formField?.touched && formField.invalid" layout="column">
89
+ <span class="error-msg" *ngFor="let err of getFieldErrors()" align="end">{{err}}</span>
90
+ </div>`,
91
+ styles: [
92
+ ':host {margin-top: -10px;}',
93
+ `.error-msg {
94
+ color: darkred;
95
+ font-size: 0.8em;
96
+ }`
97
+ ]
98
+})
99
+export class ErrorCheckerComponent {
100
+
101
+ @Input() formField: any;
102
+ @Input() fieldName: string;
103
+
104
+ constructor(private $L: LocaleService) {
105
+ }
106
+
107
+ getFieldErrors() : string[] {
108
+ if (this.formField.valid) {
109
+ return []
110
+ } else {
111
+ return (<string[]>Object.keys(this.formField.errors)).map((err:string) => this.getErrorMsg(err));
112
+ }
113
+ }
114
+
115
+ private updateFieldErrors() {
116
+ }
117
+
118
+ private getErrorMsg(err: string) : string{
119
+ switch(err) {
120
+ case 'required': {
121
+ return this.fieldName + ' '+ this.$L.get('is required');
122
+ }
123
+ case 'number': {
124
+ return this.fieldName + ' '+ this.$L.get('should be a number');
125
+ }
126
+ default: {
127
+ return this.fieldName + ' '+ this.$L.get('unknown error') + ' ' + err;
128
+ }
129
+ }
130
+ }
131
+
132
+ log(obj: any) {
133
+ console.log(obj)
134
+ }
135
+
136
+}
137
+
138
+
139
+@Component({
140
+ selector: 'field-readonly',
141
+ template: `
142
+ <div layout="column" class="mat-input-container readonly" >
143
+ <div class="mat-input-wrapper">
144
+ <div class="mat-input-table">
145
+ <div class="mat-input-prefix"></div>
146
+ <div class="mat-input-infix">
147
+ <div class="label-value mat-input-element">{{value}}</div>
148
+ <span class="mat-input-placeholder-wrapper" >
149
+ <label class="mat-input-placeholder mat-float">
150
+ <span class="placeholder">{{label}}</span>
151
+ </label>
152
+ </span>
153
+ </div>
154
+ <div class="mat-input-suffix"></div>
155
+ </div>
156
+ <div class="mat-input-underline"></div>
157
+ </div>
158
+ </div>`,
159
+ styles: [`.readonly .mat-input-element {
160
+ margin-top: 0px !important;
161
+ color: rgba(0, 0, 0, 0.50);
162
+ }`,
163
+ `.readonly .mat-input-element {
164
+ margin-top: 0px;
165
+ color: rgba(0, 0, 0, 0.50);
166
+ }`,
167
+ `.readonly.mat-input-container {
168
+ width: 100%;
169
+ }`]
170
+})
171
+export class FieldReadonlyComponent {
172
+ @Input('value') value: any;
173
+
174
+ private _label : string;
175
+ @Input('label')
176
+ set label(txt: string) {
177
+ this._label = this.$L.get(txt);
178
+ }
179
+ get label(): string { return this._label; }
180
+
181
+ constructor(private $L : LocaleService) {
182
+
183
+ }
184
+}
185
+
186
+interface MetadataPair {
187
+ key: string,
188
+ value: string,
189
+ readonly: boolean,
190
+ mandatory: boolean
191
+}
192
+
193
+@Component({
194
+ selector: 'metadata-manager',
195
+ template: `
196
+ <div layout="column" layout-fill flex>
197
+ <div layout="row" layout-align="start center">
198
+ <span class="md-title">{{title}}</span>
199
+ <span flex></span>
200
+ <button *ngIf="addOrDelete" type="button" md-icon-button color="primary" (click)="newMetadata()"><md-icon>add</md-icon></button>
201
+ </div>
202
+ <div layout="row" layout-align="start center" *ngFor="let pair of metadata" class="values">
203
+ <md-input-container flex="35" >
204
+ <input mdInput type="text" [ngModelOptions]="{standalone: true}" [(ngModel)]="pair.key" [readonly]="!editKeys" [mdTooltip]="pair.key" />
205
+ <md-placeholder>
206
+ <span i18n="field.key"></span>
207
+ </md-placeholder>
208
+ </md-input-container>
209
+ <md-input-container flex >
210
+ <input mdInput type="text" [ngModelOptions]="{standalone: true}" [(ngModel)]="pair.value" [readonly]="pair.readonly" [required]="pair.mandatory"
211
+ [mdTooltip]="pair.value" />
212
+ <md-placeholder>
213
+ <span i18n="field.value"></span>
214
+ </md-placeholder>
215
+ </md-input-container>
216
+ <md-checkbox *ngIf="addOrDelete" [ngModelOptions]="{standalone: true}" [(ngModel)]="pair.mandatory" name="mandatory" [mdTooltip]="$L.get('field.mandatory')">
217
+ </md-checkbox>
218
+ <button *ngIf="addOrDelete" type="button" md-icon-button color="warn" (click)="deleteMetadata(pair)"><md-icon>delete</md-icon></button>
219
+ </div>
220
+ </div>`,
221
+ styles: [
222
+ ':host { width:100%; }',
223
+ `.values > * {
224
+ margin-left: 5px;
225
+ margin-right: 5px;
226
+ }`
227
+ ]
228
+})
229
+export class MetadataManagerComponent {
230
+ @Input('metadata') metadata: MetadataPair[];
231
+ @Input('addOrDelete') addOrDelete: boolean = false;
232
+ @Input('editKeys') editKeys: boolean = false;
233
+ @Input('title') title: string;
234
+
235
+ constructor(private $L : LocaleService) {
236
+ this.title = $L.get('License metadata');
237
+ }
238
+
239
+ newMetadata() : void{
240
+ this.metadata.push(<MetadataPair>{
241
+ mandatory: false,
242
+ readonly: false
243
+ });
244
+ }
245
+
246
+ deleteMetadata(pair: MetadataPair) : void {
247
+ let indexToRemove = this.metadata.findIndex(ele => ele.key === pair.key);
248
+ if (indexToRemove !== -1) {
249
+ this.metadata.splice(indexToRemove, 1);
250
+ }
251
+ }
252
+}
securis/src/main/webapp/src/app/forms/license.form.component.ts
....@@ -7,7 +7,7 @@
77 import { AfterViewInit, Component, ViewChild } from '@angular/core';
88 import { ActivatedRoute, Router } from '@angular/router';
99
10
-import { TdMediaService, TdFileInputComponent } from '@covalent/core';
10
+import { TdMediaService, TdFileInputComponent, TdDialogService } from '@covalent/core';
1111 import { FormBase, IComboOption } from './base';
1212 import { ToastsManager } from "ng2-toastr/ng2-toastr";
1313
....@@ -20,11 +20,7 @@
2020 export class LicenseFormComponent extends FormBase {
2121
2222 @ViewChild('requestFileUploader') requestFileUploader : TdFileInputComponent;
23
- form_title: string = '';
24
- form_subtitle: string = '';
25
- data: any = {};
2623 pack: any = null;
27
- isNew : boolean = true;
2824
2925 constructor(private http: Http,
3026 private licenses: LicensesService,
....@@ -32,8 +28,9 @@
3228 private packs: PacksService,
3329 toaster: ToastsManager,
3430 route: ActivatedRoute,
35
- $L: LocaleService) {
36
- super($L, route, toaster, licenses, $L.get('license'));
31
+ $L: LocaleService,
32
+ dialogs: TdDialogService) {
33
+ super($L, route, toaster, licenses, $L.get('license'), dialogs);
3734 }
3835
3936 requestFileSelected(file: File) : void {
....@@ -41,7 +38,7 @@
4138 console.log(this.requestFileUploader);
4239 if (!window.FileReader) { // Browser is not
4340 // compatible
44
- console.log(this.$L.get("Open your .req file with a text editor and copy&paste the content in the form text field?"));
41
+ console.log(this.$L.get("Open your .req file with a text editor and copy&paste the content in the form text field"));
4542 return;
4643 }
4744 var reader = new FileReader();
....@@ -54,6 +51,7 @@
5451 this.requestFileUploader.clear();
5552 }
5653
54
+
5755 requestFileUploaded(file: File) : void {
5856 console.log(file);
5957 }
....@@ -82,10 +80,16 @@
8280
8381 this.route.params.subscribe(params => {
8482 var packId = +params['packId']; // (+) converts string 'id' to a number
85
- super.prepareData('licenseId', {
83
+ super.prepareInitialData('licenseId', {
8684 pack_id: packId,
8785 activation_code: this.createActivationCode()
8886 });
87
+ this.packs.get(packId).subscribe(
88
+ packData => {
89
+ this.pack = packData;
90
+ },
91
+ err => console.error(err)
92
+ );
8993 });
9094 }
9195 }
securis/src/main/webapp/src/app/forms/license.form.html
....@@ -3,7 +3,7 @@
33 <button md-icon-button (click)="goBack()" color="accent">
44 <md-icon>arrow_back</md-icon>
55 </button>
6
- <span>{{form_title}}</span>
6
+ <span [innerText]="form_title"></span>
77 <span flex></span>
88 <button md-icon-button (click)="save()"><md-icon>save</md-icon></button>
99 <md-toolbar-row class="inner-padding" *ngIf="!!pack" >
....@@ -91,23 +91,8 @@
9191 <field-readonly [value]="data.created_by_id" label="field.created_by" flex></field-readonly>
9292 <field-readonly [value]="data.creation_date | date: 'medium'" label="field.creation_date" flex></field-readonly>
9393 </div>
94
- <div layout="column" layout-fill>
95
- <span class="md-title" i18n>License metadata</span>
96
- <div layout="row" layout-fill layout-padding *ngFor="let pair of pack?.metadata">
97
- <md-input-container flex="40">
98
- <input mdInput type="text" [ngModelOptions]="{standalone: true}" [(ngModel)]="pair.key" readonly />
99
- <md-placeholder>
100
- <span i18n="field.key"></span>
101
- </md-placeholder>
102
- </md-input-container>
103
- <md-input-container flex>
104
- <input mdInput type="text" [ngModelOptions]="{standalone: true}" [(ngModel)]="pair.value" readonly />
105
- <md-placeholder>
106
- <span i18n="field.value"></span>
107
- </md-placeholder>
108
- </md-input-container>
109
- </div>
110
- </div>
94
+ <metadata-manager [addOrDelete]="false" [editKeys]="false" [metadata]="data.metadata" ></metadata-manager>
95
+
11196 </div>
11297 </form>
11398 </md-card-content>
securis/src/main/webapp/src/app/forms/pack.form.component.ts
....@@ -5,7 +5,7 @@
55 import { LicenseTypesService } from '../resources/license_types';
66 import { LocaleService } from '../common/i18n';
77 import { TdDataTableService, TdDataTableSortingOrder, ITdDataTableSortChangeEvent, ITdDataTableColumn } from '@covalent/core';
8
-import { IPageChangeEvent } from '@covalent/core';
8
+import { TdDialogService } from '@covalent/core';
99 import { Component, AfterViewInit } from '@angular/core';
1010 import { TdMediaService } from '@covalent/core';
1111 import { IComboOption, FormBase } from './base';
....@@ -21,39 +21,16 @@
2121
2222 organizations : IComboOption[];
2323 licensetypes : IComboOption[];
24
- data: any = {};
25
- isNew : boolean = true;
26
- fields: any = {
27
- 'code': '',
28
- 'num_licenses': '',
29
- 'init_valid_date': '',
30
- 'end_valid_date': '',
31
- 'license_preactivation': '',
32
- 'license_type_id': '',
33
- 'organization_id': '',
34
- 'licensetype_code': '',
35
- 'organization_name': '',
36
- 'preactivation_valid_period': '',
37
- 'renew_valid_period': '',
38
- 'application_name': '',
39
- 'status': '',
40
- 'metadata': '',
41
- 'comments': '',
42
- 'key': '',
43
- 'value': '',
44
- }
24
+
4525 constructor(private http: Http,
46
- toaster: ToastsManager,
4726 private licenseTypes: LicenseTypesService,
48
- route: ActivatedRoute,
4927 private router: Router,
5028 private packs: PacksService,
51
- $L: LocaleService) {
52
- super($L, route, toaster, packs, $L.get('pack'));
53
- }
54
-
55
- public getFieldName(fieldId: string) : string {
56
- return this.fields[fieldId];
29
+ toaster: ToastsManager,
30
+ route: ActivatedRoute,
31
+ $L: LocaleService,
32
+ dialogs: TdDialogService) {
33
+ super($L, route, toaster, packs, $L.get('pack'), dialogs);
5734 }
5835
5936 loadCombos(): void {
....@@ -93,14 +70,10 @@
9370 console.log(this.data.organization_id);
9471 }
9572
96
- ngOnInit(): void {
97
-
98
- }
99
-
10073
10174 ngAfterViewInit(): void {
10275 this.loadCombos();
103
- super.prepareData('packId', {
76
+ super.prepareInitialData('packId', {
10477 status: PACK_STATUS.CREATED
10578 });
10679 }
securis/src/main/webapp/src/app/forms/pack.form.html
....@@ -3,7 +3,7 @@
33 <button md-icon-button (click)="goBack()" color="accent">
44 <md-icon>arrow_back</md-icon>
55 </button>
6
- <span class="md-title" i18n>{{form_title}}</span>
6
+ <span class="md-title" [innerText]="form_title"></span>
77 <span flex></span>
88 <button md-icon-button (click)="save()"><md-icon>save</md-icon></button>
99 </md-toolbar>
....@@ -126,24 +126,7 @@
126126 <field-readonly [value]="data.created_by_name" label="field.created_by" flex></field-readonly>
127127 <field-readonly [value]="data.creation_timestamp | date: 'medium'" label="field.creation_timestamp" flex></field-readonly>
128128 </div>
129
- <div layout="column" layout-fill>
130
- <span class="md-title" i18n>License metadata</span>
131
- <div layout="row" layout-fill layout-padding *ngFor="let pair of data.metadata">
132
- <md-input-container flex="40">
133
- <input mdInput type="text" [ngModelOptions]="{standalone: true}" [(ngModel)]="pair.key" readonly />
134
- <md-placeholder>
135
- <span i18n="field.key"></span>
136
- </md-placeholder>
137
- </md-input-container>
138
- <md-input-container flex>
139
- <input mdInput type="text" [ngModelOptions]="{standalone: true}" [(ngModel)]="pair.value" [readonly]="pair.readonly" [required]="pair.required"
140
- />
141
- <md-placeholder>
142
- <span i18n="field.value"></span>
143
- </md-placeholder>
144
- </md-input-container>
145
- </div>
146
- </div>
129
+ <metadata-manager [addOrDelete]="false" [editKeys]="false" [metadata]="data.metadata" ></metadata-manager>
147130 </div>
148131 </form>
149132 </md-card-content>
securis/src/main/webapp/src/app/listing/application.list.component.html
....@@ -26,7 +26,6 @@
2626 <template tdDataTableTemplate="menu" let-row="row" let-index="index">
2727 <div layout="row" layout-align="end center">
2828 <button md-icon-button (click)="edit(row.id)" color="primary"><md-icon>edit</md-icon></button>
29
- <button md-icon-button (click)="delete(row)" color="warn"><md-icon>delete</md-icon></button>
3029 </div>
3130 </template>
3231 </td-data-table>
securis/src/main/webapp/src/app/listing/pack.list.component.ts
....@@ -104,8 +104,8 @@
104104 this.router.navigate([`create`], {relativeTo: this.route});
105105 }
106106
107
- edit(pack: any) : void {
108
- this.router.navigate([`edit/${pack.id}`], {relativeTo: this.route});
107
+ edit(packId: number) : void {
108
+ this.router.navigate([`edit/${packId}`], {relativeTo: this.route});
109109 }
110110
111111 sort(sortEvent: ITdDataTableSortChangeEvent): void {
securis/src/main/webapp/src/app/resources/applications.ts
....@@ -2,6 +2,7 @@
22 import { Injectable } from '@angular/core';
33 import { Http, RequestOptions } from '@angular/http';
44 import { SeCurisResourceServices } from './base';
5
+import { LocaleService } from '../common/i18n';
56
67 var app_example = { code: 'CICS',
78 creation_timestamp: 1418384439000,
....@@ -17,8 +18,8 @@
1718
1819 @Injectable()
1920 export class ApplicationsService extends SeCurisResourceServices {
20
- constructor(http: Http) {
21
- super(http, 'application');
21
+ constructor(http: Http, $L: LocaleService) {
22
+ super($L, http, 'application');
2223 }
2324
2425
securis/src/main/webapp/src/app/resources/base.ts
....@@ -1,3 +1,5 @@
1
+import { LocaleService } from '../common/i18n';
2
+import { BasicService } from '../common/utils';
13 import { Observable } from 'rxjs/Observable';
24 import { Http, RequestOptionsArgs, URLSearchParams } from '@angular/http';
35
....@@ -8,29 +10,31 @@
810 }
911 }
1012
11
-export class SeCurisResourceServices {
12
- constructor(protected http: Http,
13
+export class SeCurisResourceServices extends BasicService {
14
+ constructor($L: LocaleService,
15
+ protected http: Http,
1316 protected resource: string) {
17
+ super($L);
1418 }
1519
1620 public get(id?: any) : Observable<any> {
1721 let url = `${this.resource}/${id || ''}`;
18
- return this.http.get(url).map(response => response.json());
22
+ return this.http.get(url).map(response => response.json()).catch(err => super.processErrorResponse(err));
1923 }
2024
2125 public create(data: any) : Observable<any> {
2226 let url = `${this.resource}`;
23
- return this.http.post(url, JSON.stringify(data)).map(response => response.json());
27
+ return this.http.post(url, JSON.stringify(data)).map(response => response.json()).catch(err => super.processErrorResponse(err));
2428 }
2529
2630 public modify(id: any, data: any) : Observable<any> {
2731 let url = `${this.resource}/${id}`;
28
- return this.http.post(url, JSON.stringify(data)).map(response => response.json());
32
+ return this.http.post(url, JSON.stringify(data)).map(response => response.json()).catch(err => super.processErrorResponse(err));
2933 }
3034
3135 public remove(id: any) : Observable<any> {
3236 let url = `${this.resource}/${id}`;
33
- return this.http.delete(url).map(response => response.json());
37
+ return this.http.delete(url).map(response => response.json()).catch(err => super.processErrorResponse(err));
3438 }
3539
3640 public action(id: any, action: string, method = 'POST') : Observable<any> {
....@@ -44,6 +48,8 @@
4448 search: (method == 'GET') && new MySearchParams(params) || undefined,
4549 body: (method == 'POST') && JSON.stringify(params) || undefined
4650 };
47
- return this.http.request(url, options).map(response => response.json());
51
+ return this.http.request(url, options).map(response => response.json()).catch(err => super.processErrorResponse(err));
4852 }
53
+
54
+
4955 }
securis/src/main/webapp/src/app/resources/license_types.ts
....@@ -2,6 +2,7 @@
22 import { Injectable } from '@angular/core';
33 import { Http, RequestOptions } from '@angular/http';
44 import { SeCurisResourceServices } from './base';
5
+import { LocaleService } from '../common/i18n';
56
67 var lictype_example = { application_name: 'CurisIntegrity',
78 code: 'CIA2',
....@@ -14,8 +15,8 @@
1415
1516 @Injectable()
1617 export class LicenseTypesService extends SeCurisResourceServices {
17
- constructor(http: Http) {
18
- super(http, 'licensetype');
18
+ constructor(http: Http, $L: LocaleService) {
19
+ super($L, http, 'licensetype');
1920 }
2021
2122
securis/src/main/webapp/src/app/resources/licenses.ts
....@@ -60,8 +60,8 @@
6060 @Injectable()
6161 export class LicensesService extends SeCurisResourceServices {
6262 constructor(http: Http,
63
- private $L: LocaleService) {
64
- super(http, 'license');
63
+ $L: LocaleService) {
64
+ super($L, http, 'license');
6565 }
6666
6767 public getByPack(packId: number) {
securis/src/main/webapp/src/app/resources/organizations.ts
....@@ -2,6 +2,7 @@
22 import { Injectable } from '@angular/core';
33 import { Http, RequestOptions } from '@angular/http';
44 import { SeCurisResourceServices } from './base';
5
+import { LocaleService } from '../common/i18n';
56
67 var org_example = { code: 'NPS',
78 creation_timestamp: 1488269722000,
....@@ -11,8 +12,8 @@
1112
1213 @Injectable()
1314 export class OrganizationsService extends SeCurisResourceServices {
14
- constructor(http: Http) {
15
- super(http, 'organization');
15
+ constructor(http: Http, $L: LocaleService) {
16
+ super($L, http, 'organization');
1617 }
1718
1819
securis/src/main/webapp/src/app/resources/packs.ts
....@@ -60,8 +60,8 @@
6060
6161 @Injectable()
6262 export class PacksService extends SeCurisResourceServices {
63
- constructor(http: Http, private $L: LocaleService) {
64
- super(http, 'pack');
63
+ constructor(http: Http, $L: LocaleService) {
64
+ super($L, http, 'pack');
6565 }
6666
6767 public activate(id: number) {
securis/src/main/webapp/src/app/resources/users.ts
....@@ -2,6 +2,7 @@
22 import { Injectable } from '@angular/core';
33 import { Http, RequestOptions } from '@angular/http';
44 import { SeCurisResourceServices } from './base';
5
+import { LocaleService } from '../common/i18n';
56
67 var user_example = {
78 creation_timestamp: 1479898458000,
....@@ -17,8 +18,8 @@
1718
1819 @Injectable()
1920 export class UsersService extends SeCurisResourceServices {
20
- constructor(http: Http) {
21
- super(http, 'user');
21
+ constructor(http: Http, $L: LocaleService) {
22
+ super($L, http, 'user');
2223 }
2324
2425
securis/src/main/webapp/src/app/user.service.ts
....@@ -1,4 +1,5 @@
11 import { LocaleService } from './common/i18n';
2
+import { BasicService } from './common/utils';
23 import { Injectable } from '@angular/core';
34 import { Router } from '@angular/router';
45 import { Location } from '@angular/common';
....@@ -10,15 +11,15 @@
1011 const SECURIS_TOKEN = "X-SECURIS-TOKEN";
1112
1213 @Injectable()
13
-export class UserService {
14
+export class UserService extends BasicService {
1415
1516 count : number = 0;
1617
17
- constructor(private $L: LocaleService,
18
+ constructor($L: LocaleService,
1819 private router: Router,
1920 private store: LocalStorageService,
2021 private http: Http) {
21
-
22
+ super($L);
2223 }
2324
2425 public login(username: string, password: string) : Observable<string> {
....@@ -28,7 +29,7 @@
2829 let options = new RequestOptions({ headers: new Headers({ "Content-Type": "application/x-www-form-urlencoded" })});
2930 return this.http.post('user/login', params.toString(), options)
3031 .map((resp) => this.mapLogin(resp))
31
- .catch((err) => this.handleError(err));
32
+ .catch((err) => super.processErrorResponse(err));
3233 }
3334
3435 private mapLogin(res : Response) : string {
....@@ -36,6 +37,7 @@
3637 this.store.set('user_full_name', data.full_name);
3738 this.store.set('username', data.username);
3839 this.store.set('token', data.token);
40
+ console.log('New login token: ' + data.token);
3941 return <string>data.token;
4042 }
4143
....@@ -47,7 +49,7 @@
4749 let option = new RequestOptions({ headers: new Headers({ 'X-SECURIS-TOKEN': token }) });
4850 return this.http.get('check', option)
4951 .map((resp) => this.mapCheck(resp))
50
- .catch((err) => this.handleError(err));
52
+ .catch((err) => super.processErrorResponse(err));
5153 }
5254
5355 private mapCheck(res : Response) : boolean {
....@@ -67,29 +69,6 @@
6769 this.router.navigate(['public/login']);
6870 }
6971
70
-
71
- private handleError (error: Response | any) {
72
- // In a real world app, we might use a remote logging infrastructure
73
- let errMsg: string;
74
- if (error instanceof Response) {
75
- const err = JSON.stringify(error);
76
- errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
77
- } else {
78
- errMsg = error.message ? error.message : error.toString();
79
- }
80
-
81
- if (error.status === 403 /* forbidden */ || error.status === 401 /* unauthorized */) {
82
- errMsg = this.$L.get('Invalid credentials');
83
- } else if (error.status === 418 /* Teapot */) {
84
- errMsg = this.$L.get(error.headers.get('X-SECURIS-ERROR-MSG'));
85
- } else {
86
- console.error(error);
87
- errMsg = this.$L.get(`Unexpected error HTTP (${error.status}) accessing to server. Contact with the administrator.`);
88
- }
89
-
90
- console.error(errMsg);
91
- return Observable.throw(errMsg);
92
- }
9372
9473 }
9574
securis/src/main/webapp/src/lang/messages_en.json
....@@ -26,6 +26,10 @@
2626 "field.email": "Email",
2727 "field.creation_timestamp": "Creation timestamp",
2828 "field.comments": "Comments",
29
+ "field.mandatory": "Required",
30
+ "field.name": "Name",
31
+ "field.license_filename": "License filename",
32
+ "field.description": "Description",
2933 "pack.status.CR": "Created",
3034 "pack.status.AC": "Active",
3135 "pack.status.OH": "On Hold",