add subtype to resources
This commit is contained in:
parent
1f801cb4bf
commit
1a6cc4ae2a
|
@ -25,11 +25,12 @@ public class ResourceAjaxController extends AbstractResourceController {
|
|||
@PostMapping("/")
|
||||
public SimpleResource newResource(@RequestParam final String name,
|
||||
@RequestParam final String type,
|
||||
@RequestParam(required = false, defaultValue = "") final String subtype,
|
||||
@RequestParam(required = false, defaultValue = "") final String description,
|
||||
@RequestParam final String content)
|
||||
throws InformationServiceException {
|
||||
|
||||
return service.saveNewResource(name, type, description, content);
|
||||
return service.saveNewResource(name, type, subtype, description, content);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{resId}")
|
||||
|
|
|
@ -54,6 +54,7 @@ export interface SimpleResource {
|
|||
id: string,
|
||||
name: string,
|
||||
type: string,
|
||||
subtype?: string,
|
||||
description?: string,
|
||||
creationDate?: string,
|
||||
modificationDate?: string
|
||||
|
|
|
@ -72,11 +72,12 @@ export class ISService {
|
|||
});
|
||||
}
|
||||
|
||||
addSimpleResource(name: string, type: string, description: string, content: string, onSuccess: Function, relatedForm?: FormGroup): void {
|
||||
addSimpleResource(name: string, type: string, subtype: string, description: string, content: string, onSuccess: Function, relatedForm?: FormGroup): void {
|
||||
const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
|
||||
let body = new HttpParams()
|
||||
.set('name', name)
|
||||
.set('type', type)
|
||||
.set('subtype', subtype)
|
||||
.set('description', description)
|
||||
.set('content', content);
|
||||
this.client.post<void>('/ajax/resources/', body, { headers: headers }).subscribe({
|
||||
|
|
|
@ -13,9 +13,14 @@
|
|||
<input matInput readonly value="{{data.type}}" />
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="fill" floatLabel="always" style="width: 100%;">
|
||||
<mat-label>SubType (optional)</mat-label>
|
||||
<input matInput formControlName="subtype" />
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="fill" floatLabel="always" style="width: 100%;">
|
||||
<mat-label>Name</mat-label>
|
||||
<input matInput formControlName="name" required />
|
||||
<input matInput formControlName="name" />
|
||||
<mat-error *ngIf="metadataForm.get('name')?.invalid">This field is <strong>required</strong></mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
|
|
|
@ -5,10 +5,15 @@
|
|||
|
||||
<mat-form-field appearance="fill" floatLabel="always" style="width: 100%;">
|
||||
<mat-label>Name</mat-label>
|
||||
<input matInput formControlName="name" required />
|
||||
<input matInput formControlName="name" />
|
||||
<mat-error *ngIf="newResourceForm.get('name')?.invalid">This field is <strong>required</strong></mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="fill" floatLabel="always" style="width: 100%;">
|
||||
<mat-label>SubType (optional)</mat-label>
|
||||
<input matInput formControlName="subtype" />
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="fill" floatLabel="always" style="width: 100%;">
|
||||
<mat-label>Description</mat-label>
|
||||
<textarea matInput formControlName="description" rows="2"></textarea>
|
||||
|
@ -16,7 +21,7 @@
|
|||
|
||||
<mat-form-field appearance="fill" floatLabel="always" style="width: 100%;">
|
||||
<mat-label>Content ({{data.contentType}})</mat-label>
|
||||
<textarea matInput formControlName="content" required rows="10" style="font-size: 0.8em;"></textarea>
|
||||
<textarea matInput formControlName="content" rows="10" style="font-size: 0.8em;"></textarea>
|
||||
<mat-error *ngIf="newResourceForm.get('content')?.invalid">This field is <strong>required</strong></mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
|
|
|
@ -12,14 +12,18 @@
|
|||
|
||||
<mat-card *ngFor="let r of resources | searchFilter: searchText" style="margin-top: 10px;">
|
||||
<mat-card-header>
|
||||
<mat-card-title title="{{r.id}}">{{r.name}} <span class="badge-label badge-info"
|
||||
style="font-size: 0.7em;">{{type.contentType}}</span></mat-card-title>
|
||||
<mat-card-title title="{{r.id}}">
|
||||
{{r.name}}
|
||||
<span class="badge-label badge-warning" style="font-size: 0.7em;" *ngIf="r.subtype">{{r.subtype}}</span>
|
||||
<span class="badge-label badge-info" style="font-size: 0.7em;">{{type.contentType}}</span>
|
||||
</mat-card-title>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<p>{{r.description}}</p>
|
||||
<p class="muted small">
|
||||
<b>Id:</b> {{r.id}}<br /> <b>Creation date:</b> {{r.creationDate}}<br /> <b>Modification date:</b>
|
||||
{{r.modificationDate}}
|
||||
<b>Id:</b> {{r.id}}<br />
|
||||
<b>Creation date:</b> {{r.creationDate}}<br />
|
||||
<b>Modification date:</b> {{r.modificationDate}}
|
||||
</p>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
|
|
|
@ -3,7 +3,7 @@ import { ISService } from '../common/is.service';
|
|||
import { ActivatedRoute } from '@angular/router';
|
||||
import { MatDialog, MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { ResourceType, SimpleResource } from '../common/is.model';
|
||||
import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'app-resources',
|
||||
|
@ -115,12 +115,16 @@ export class ResContentDialog {
|
|||
})
|
||||
export class ResMetadataDialog {
|
||||
metadataForm = new FormGroup({
|
||||
name: new FormControl(''),
|
||||
name: new FormControl('', [Validators.required]),
|
||||
subtype: new FormControl(''),
|
||||
description: new FormControl('')
|
||||
});
|
||||
|
||||
constructor(public dialogRef: MatDialogRef<ResMetadataDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) {
|
||||
this.metadataForm.get('name')?.setValue(data.name);
|
||||
if (data.subtype) {
|
||||
this.metadataForm.get('subtype')?.setValue(data.subtype);
|
||||
}
|
||||
if (data.description) {
|
||||
this.metadataForm.get('description')?.setValue(data.description);
|
||||
}
|
||||
|
@ -143,9 +147,10 @@ export class ResMetadataDialog {
|
|||
})
|
||||
export class ResCreateNewDialog {
|
||||
newResourceForm = new FormGroup({
|
||||
name: new FormControl(''),
|
||||
name: new FormControl('', [Validators.required]),
|
||||
subtype: new FormControl(''),
|
||||
description: new FormControl(''),
|
||||
content: new FormControl('')
|
||||
content: new FormControl('', [Validators.required])
|
||||
});
|
||||
|
||||
constructor(public dialogRef: MatDialogRef<ResCreateNewDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) { }
|
||||
|
@ -153,10 +158,11 @@ export class ResCreateNewDialog {
|
|||
onSubmit(): void {
|
||||
let name: string = this.newResourceForm.get('name')?.value!;
|
||||
let type: string = this.data.id!;
|
||||
let subtype: string = this.newResourceForm.get('subtype')?.value!;
|
||||
let description: string = this.newResourceForm.get('description')?.value!;
|
||||
let content: string = this.newResourceForm.get('content')?.value!;
|
||||
|
||||
this.service.addSimpleResource(name, type, description, content, (data: void) => this.dialogRef.close(1), this.newResourceForm);
|
||||
this.service.addSimpleResource(name, type, subtype, description, content, (data: void) => this.dialogRef.close(1), this.newResourceForm);
|
||||
}
|
||||
onNoClick(): void {
|
||||
this.dialogRef.close();
|
||||
|
|
|
@ -24,6 +24,9 @@ public class SimpleResource implements Serializable {
|
|||
@Column(name = "type")
|
||||
private String type;
|
||||
|
||||
@Column(name = "subtype")
|
||||
private String subtype;
|
||||
|
||||
@Column(name = "description")
|
||||
private String description;
|
||||
|
||||
|
@ -57,6 +60,14 @@ public class SimpleResource implements Serializable {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public String getSubtype() {
|
||||
return subtype;
|
||||
}
|
||||
|
||||
public void setSubtype(final String subtype) {
|
||||
this.subtype = subtype;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
|
|
@ -139,6 +139,7 @@ CREATE TABLE resources (
|
|||
description text,
|
||||
content text NOT NULL DEFAULT '',
|
||||
type text NOT NULL REFERENCES resource_types(id),
|
||||
subtype text,
|
||||
creation_date timestamp NOT NULL DEFAULT now(),
|
||||
modification_date timestamp NOT NULL DEFAULT now()
|
||||
);
|
||||
|
|
|
@ -60,6 +60,7 @@ public class SimpleResourceService {
|
|||
@Transactional
|
||||
public SimpleResource saveNewResource(final String name,
|
||||
final String type,
|
||||
final String subtype,
|
||||
final String description,
|
||||
final String content) throws InformationServiceException {
|
||||
|
||||
|
@ -71,6 +72,7 @@ public class SimpleResourceService {
|
|||
res.setId(UUID.randomUUID().toString());
|
||||
res.setName(name);
|
||||
res.setType(type);
|
||||
res.setSubtype(subtype);
|
||||
res.setDescription(description);
|
||||
res.setCreationDate(now);
|
||||
res.setModificationDate(now);
|
||||
|
|
Loading…
Reference in New Issue