Skip to content

Commit

Permalink
https://github.com/DASISH/qddt-client/issues/769
Browse files Browse the repository at this point in the history
  • Loading branch information
StigNorland committed Jan 19, 2022
1 parent 4508236 commit 07a32cd
Show file tree
Hide file tree
Showing 20 changed files with 58 additions and 111 deletions.
2 changes: 1 addition & 1 deletion src/app/components/footer/elementfooter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ElementFooterComponent {
getVersion(): string {
const v = this.element.version;
if (!v) { return '?'; }
const rev = (v.revision) ? '.' + v.revision : '';
const rev = (v.rev) ? '.' + v.rev : '';
const label = (v.versionLabel) ? ' - ' + v.versionLabel : '';
return v.major + '.' + v.minor + rev + label;
}
Expand Down
16 changes: 1 addition & 15 deletions src/app/lib/classes/classes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ElementKind } from '../enums';
import { IEntityAudit, IPageSearch, IRevisionResult, IUser, ISurveyOrder } from '../interfaces';
import { IPageSearch, ISurveyOrder } from '../interfaces';

export class QueryInfo {
id: ElementKind;
Expand Down Expand Up @@ -40,20 +40,6 @@ const lowerFirstLetter = ([first, ...rest]: string, locale = navigator.language)
first.toLocaleLowerCase(locale) + rest.join('')


export class RevisionResult<T extends IEntityAudit> {
entity: T;
revisionModifiedBy: IUser;
revisionDate: any;
revisionNumber: number;
constructor(init?: Partial<IRevisionResult<T>>) {
this.entity = init.entity;
this.revisionDate = init.metadata.revisionDate;
this.revisionNumber = init.metadata.revisionNumber;
this.revisionModifiedBy = init.metadata.delegate.modifiedBy;
}
}


/*
* number: the current page beginning with zero
* size: the size of each page
Expand Down
9 changes: 8 additions & 1 deletion src/app/lib/classes/publication.classes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ElementKind } from '../enums';
import { IComment, ISelectOption, IEntityEditAudit} from '../interfaces';
import { IComment, ISelectOption, IEntityEditAudit, HalLink} from '../interfaces';
import { ElementRevisionRef } from './element-revision-ref';
import { Agency } from './user.classes';

Expand All @@ -14,6 +14,13 @@ export class Publication implements IEntityEditAudit {
agency?: Agency;
publicationElements: ElementRevisionRef[] = [];
comments?: IComment[];
_links?: {
[rel: string]: HalLink;
};
_embedded?: {
[rel: string]: any;
};
pu
public constructor(init?: Partial<Publication>) {
Object.assign(this, init);
}
Expand Down
1 change: 0 additions & 1 deletion src/app/lib/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './entity-edit-audit';
export * from './http.interfaces';
export * from './interfaces';
export * from './revision-result-entity';
2 changes: 1 addition & 1 deletion src/app/lib/interfaces/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export interface IVersion {
major: string | number;
minor: string | number;
versionLabel?: string;
revision?: string | number;
rev?: number;
}

export interface IOtherMaterial {
Expand Down
16 changes: 0 additions & 16 deletions src/app/lib/interfaces/revision-result-entity.ts
Original file line number Diff line number Diff line change
@@ -1,16 +0,0 @@
import { IUser , IEntityEditAudit, IEntityAudit} from '.';

export interface IRevisionResultEntity extends IRevisionResult<IEntityEditAudit>{
entity: IEntityEditAudit;
revisionmodifiedBy?: IUser|string;
metadata: { delegate: { id: number, timestamp: number, modifiedBy: IUser }, revisionDate: any, revisionNumber: number };
revisionDate: any;
revisionNumber: number;
}

export interface IRevisionResult<T extends IEntityAudit> {
entity: T;
metadata: { delegate: { id: number, timestamp: number, modifiedBy: IUser }, revisionDate: any, revisionNumber: number };
revisionDate: any;
revisionNumber: number;
}
8 changes: 3 additions & 5 deletions src/app/lib/services/home.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SurveyProgram } from '../classes';
import { ElementRevisionRef, SurveyProgram } from '../classes';
import { Inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
Expand Down Expand Up @@ -76,11 +76,9 @@ export class HomeService<T extends IEntityEditAudit> {

}

attachQuestion(kind: ElementKind, id: string, questionId: string, revision: number): Observable<T> {
attachQuestion(kind: ElementKind, id: string, ref: ElementRevisionRef): Observable<T> {
const qe = getQueryInfo(kind);
if (revision === null) { revision = 0; }
return this.http.post<T>(this.api + qe.path + '/combine?questionitemid=' + questionId +
'&questionitemrevision=' + revision + '&parentId=' + id, {});
return this.http.post<T>(this.api + qe.path + '/' + id + '/questionitems', ref);
}

deattachQuestion(kind: ElementKind, id: string, questionId: string, revision: number): Observable<T> {
Expand Down
23 changes: 5 additions & 18 deletions src/app/lib/services/preview.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http';
import { API_BASE_HREF } from '../../api';
import { ElementKind } from '../enums';
import { getQueryInfo, getElementKind } from '../consts';
import { IEntityEditAudit, IOtherMaterial, IRevisionResult } from '../interfaces';
import { IEntityEditAudit, IOtherMaterial } from '../interfaces';
import { ElementRevisionRefImpl, AbstractControlConstruct, isAbstractControlConstruct, SequenceConstruct } from '../classes';
import { Factory } from '../factory';

Expand All @@ -21,25 +21,12 @@ export class PreviewService {
return this.http.get(this.api + qe.path + '/' + id).toPromise();
}

public getRevisionByKind(kind: ElementKind | string, id: string, rev: number): Promise<IRevisionResult<IEntityEditAudit>> {
public getRevisionByKind(kind: ElementKind | string, id: string, rev: number): Promise<IEntityEditAudit> {

const qe = getQueryInfo(kind);
return this.http.get<IRevisionResult<IEntityEditAudit>>(this.api + '/' + qe.path + '/' + id + ':' + rev).toPromise();
return this.http.get<IEntityEditAudit>(this.api + '/' + qe.path + '/' + id + ':' + rev).toPromise();
}

// public getRevisionsByKind(kind: ElementKind | string, id: string): Promise<any> {
//
// const qe = getQueryInfo(kind);
// if (qe) {
// if (kind === ElementKind.CONCEPT || kind === ElementKind.TOPIC_GROUP) {
// return this.http.get(this.api + 'audit/' + qe.path + '/' + id + '/allinclatest').toPromise();
// } else {
// return this.http.get(this.api + 'audit/' + qe.path + '/' + id + '/all').toPromise();
// }
// }
// return new Promise(null);
// }

public getFile(om: IOtherMaterial): Promise<Blob> {
// /files/{root}/{filename}
return this.http.get(this.api + 'othermaterial/files/' + om.originalOwner + '/' + om.fileName, { responseType: 'blob' })
Expand All @@ -50,9 +37,9 @@ export class PreviewService {
// @ts-ignore
const qe = getQueryInfo(element.classKind || element.refKind);
// @ts-ignore
const revision = element.refRev || element.version.revision;
const revision = element.refRev || element.version.rev;
if (revision) {
return this.http.get(this.api + '/' + qe.path + '/' + element.id + ':' + element.version.revision + '/pdf'
return this.http.get(this.api + '/' + qe.path + '/' + element.id + ':' + element.version.rev + '/pdf'
, { responseType: 'blob' }).toPromise();
} else {
return this.http.get(this.api + '/' + qe.path + '/' + element.id + '/pdf', { responseType: 'blob' }).toPromise();
Expand Down
35 changes: 13 additions & 22 deletions src/app/lib/services/template.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { API_BASE_HREF } from '../../api';
import { UserService } from './user.service';
import { IEntityAudit, IEntityEditAudit, IPageResult, IPageSearch, IRevisionResult, IOtherMaterial, HalResource } from '../interfaces';
import { IEntityAudit, IEntityEditAudit, IPageResult, IPageSearch, IOtherMaterial, HalResource } from '../interfaces';
import { ElementKind, ActionKind } from '../enums';
import { getQueryInfo, getElementKind } from '../consts';
import { Agency, PageSearch } from '../classes';
Expand Down Expand Up @@ -76,15 +76,8 @@ export class TemplateService {
this.http.get<T>(this.api + qe.path + '/' + id).toPromise()
.then(async (result: T) => {
if (!(result._embedded)) {
console.log(result._embedded)
result._embedded = {};
}
if (!(result._embedded.agency) && (result.agencyId))
result._embedded.agency = await this.getAgency(result.agencyId);
if (!(result._embedded.modifiedBy) && (result.modifiedById))
result._embedded.modifiedBy = await this.getUser(result.modifiedById)

// Success
resolve(result);
},
err => {
Expand All @@ -95,31 +88,29 @@ export class TemplateService {
});

}
public getByKindRevisions<T extends IEntityAudit>(kind: ElementKind, id: string): Promise<IPageResult> {
const qe = getQueryInfo(kind);
if (qe) {
// if (kind === ElementKind.CONCEPT || kind === ElementKind.TOPIC_GROUP) {
// return this.http.get<IPageResult>
// (this.api + '/' + qe.path + '/' + id + '/revisions').toPromise();
// } else {
return this.http.get<IPageResult>(this.api + qe.path + '/revisions/' + id ).toPromise();
// }
}
return new Promise(null);
public getByKindRevisions<T extends IEntityAudit>(kind: ElementKind, id: string): Promise<any> {
return new Promise((resolve, reject) => {
const qe = getQueryInfo(kind);
this.http.get<HalResource>(this.api + qe.path + '/revisions/' + id).toPromise()
.then(
async result => resolve(result._embedded[qe.halName]),
err => reject(err)
);
});
}

public getByKindRevision(kind: ElementKind, id: string, rev?: number): Promise<IEntityEditAudit> {
const qe = getQueryInfo(kind);
if (rev) {
return this.http.get<IEntityEditAudit>(this.api + 'revision/'+ qe.path + '/' + id + ':' + rev).toPromise();
return this.http.get<IEntityEditAudit>(this.api + qe.path + '/revision/'+ id + ':' + rev).toPromise();
}
return this.http.get<IEntityEditAudit>(this.api + qe.path + '/' + id).toPromise();

}

public getLatestVersionByKindEntity<T extends IEntityEditAudit>(kind: ElementKind, id: string): Promise<IRevisionResult<T>> {
public getLatestVersionByKindEntity<T extends IEntityEditAudit>(kind: ElementKind, id: string): Promise<T> {
const qe = getQueryInfo(kind);
return this.http.get<IRevisionResult<T>>(this.api + 'audit/' + qe.path + '/' + id + '/latestversion').toPromise();
return this.http.get<T>(this.api + 'audit/' + qe.path + '/' + id + '/latestversion').toPromise();
}

public create<T extends IEntityAudit>(item: T, parentId?: string, putUrl?:string): Observable<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ <h5>{{ concept.name }}</h5>

<qddt-download [entity]="concept" [readonly]="true"></qddt-download>

<qddt-comment-list [ownerId]="concept.id" [comments]="concept.comments">
<qddt-comment-list [ownerId]="concept.id" [comments]="concept._embedded?.comments">
</qddt-comment-list>
<qddt-revision *ngIf="edit.showRevision" [current]="concept"></qddt-revision>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class TreeNodeComponent {
}

public onQuestionItemAdded(ref: ElementRevisionRef, conceptId) {
this.homeService.attachQuestion(this.CONCEPT, conceptId, ref.elementId, ref.elementRevision)
this.homeService.attachQuestion(this.CONCEPT, conceptId, ref)
.subscribe(result => this.onConceptUpdated(result));
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/home/study/study.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ <h5>{{ study.name }}</h5>

<qddt-revision *ngIf="edit.showRevision" [current]="study"></qddt-revision>
</ng-container>
<qddt-comment-list [hidden]="edit.isVisible" [ownerId]="study.id" [comments]="study.comments">
<qddt-comment-list [hidden]="edit.isVisible" [ownerId]="study.id" [comments]="study._embedded?.comments">
</qddt-comment-list>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/home/topic/topic.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ <h5>{{ topic.name }}</h5>

<qddt-download [entity]="topic" [readonly]="true"></qddt-download>

<qddt-comment-list [ownerId]="topic.id" [comments]="topic.comments">
<qddt-comment-list [ownerId]="topic.id" [comments]="topic._embedded?.comments">
</qddt-comment-list>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/home/topic/topic.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class TopicComponent implements OnInit {
}

public onQuestionItemAdded(ref: ElementRevisionRef, topicId) {
this.homeService.attachQuestion(this.TOPIC_KIND, topicId, ref.elementId, ref.elementRevision)
this.homeService.attachQuestion(this.TOPIC_KIND,topicId,ref)
.subscribe(result => this.onTopicSaved(result));
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ export class MenuComponent implements OnInit, OnDestroy, AfterViewInit {

private gotoUUID(uuid: string) {
this.service.searchByUuid(uuid).then((result) => {
if (result.revision) {
if (result.rev) {

this.msgService.sendMessage({
elementId: result.id,
elementRevision: result.revision,
elementRevision: result.rev,
elementKind: result.elementKind
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
(change)="getDescription(publication.statusId)" [(ngModel)]="publication.statusId" [lockups]="statusMap"
[readonly]="readonly">
</qddt-select>
<div class="col s6 m7 l8 infoText">{{publication?.status?.description}}</div>
<div class="col s6 m7 l8 infoText">{{publication?._embedded.status?.description}}</div>
</div>
<label>Content list</label>
<qddt-element-revision-ref class="row" [readonly]="readonly" [elementRevisions]="publication.publicationElements"
Expand Down
2 changes: 0 additions & 2 deletions src/app/modules/publication/publication.form.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { element } from 'protractor';

import { AfterViewInit, Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
import {
ActionKind,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CopySourceComponent } from './../../home/copysource/copy-source.component';
import { delay, hasChanges } from 'src/app/lib';
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import {
Expand All @@ -8,7 +7,6 @@ import {
getElementKind,
IElement,
IRevisionRef,
IRevisionResultEntity,
QuestionConstruct,
StatementConstruct,
QuestionItem,
Expand Down Expand Up @@ -73,7 +71,7 @@ export class ElementRevisionComponent implements OnChanges {
}
}

public onSelectedRevision(revision: IRevisionResultEntity) {
public onSelectedRevision(revision: IEntityEditAudit) {
this.revisionSelectedEvent.emit(this.getRevisionRef(revision));
this.revisionRef = null;
}
Expand All @@ -93,15 +91,15 @@ export class ElementRevisionComponent implements OnChanges {
}


private getRevisionRef(elementRevision: IRevisionResultEntity): ElementRevisionRef {
const kind = getElementKind(elementRevision.entity.classKind);
private getRevisionRef(revision: IEntityEditAudit): ElementRevisionRef {
const kind = getElementKind(revision.classKind);
return new ElementRevisionRefImpl<IEntityEditAudit>({
elementId: elementRevision.entity.id,
elementRevision: elementRevision.revisionNumber,
elementId: revision.id,
elementRevision: revision.version.rev,
elementKind: ElementKind[kind],
element: Factory.createFromSeed(ElementKind[kind], elementRevision.entity),
version: elementRevision.entity.version,
name: this.getName(kind, elementRevision.entity)
element: Factory.createFromSeed(ElementKind[kind], revision),
version: revision.version,
name: this.getName(kind, revision)
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/selectors/revision/revision.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ <h4 class="row teal-text">Preview</h4>
<label>Name</label>
</li>
<li>
<div class="black-text text-lighten-1">{{ selectedRevisionResult.entity.name }}</div>
<div class="black-text text-lighten-1">{{ selectedRevisionResult.name }}</div>
</li>
</ul>
<qddt-preview-element [element]="selectedRevisionResult.entity"></qddt-preview-element>
<qddt-preview-element [element]="selectedRevisionResult"></qddt-preview-element>
</div>
</div>
Loading

0 comments on commit 07a32cd

Please sign in to comment.