Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ import { GeoJsonService } from './services/geo-json.service';
import { PolicyRepositoryService } from './services/policy-repository.service';
import { RelayerAccountsService } from './services/relayer-accounts.service';
import { RelayerAccountsComponent } from './views/relayer-accounts/relayer-accounts.component';
import { TreeTableModule } from 'primeng/treetable'

@NgModule({
declarations: [
Expand Down Expand Up @@ -229,7 +230,9 @@ import { RelayerAccountsComponent } from './views/relayer-accounts/relayer-accou
ProjectComparisonModule,
DndModule,
CheckboxModule,
AngularSvgIconModule.forRoot()],
AngularSvgIconModule.forRoot(),
TreeTableModule
],
providers: [
WebSocketService,
AuthService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, Inject } from '@angular/core';
import { UntypedFormControl, Validators } from '@angular/forms';
import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';
import { ModelHelper } from '@guardian/interfaces';

/**
* Publish tool dialog
Expand Down Expand Up @@ -50,6 +51,8 @@ export class PublishToolDialog {
}

public get isPublishDisabled(): boolean {
return !this.versionControl.valid;
const isFormInvalid = !this.versionControl.valid;
const isVersionNotNewer = this.tool?.version && ModelHelper.versionCompare(this.tool.version, this.versionControl.value) >= 0;
return isFormInvalid || isVersionNotNewer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ <h1 class="dialog-title">Enter version</h1>
<div class="form-input-container">
<label class="form-label" htmlFor="version">* Version</label>
<input [formControl]="versionControl" id="version" pInputText type="text"/>
<div *ngIf="schema?.version" class="form-label" style="font-size: 12px; margin-top: 5px;">
Previous version: {{schema.version}}
</div>
</div>
</div>
<div class="content dialog-actions">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Component, Inject} from '@angular/core';
import {UntypedFormControl, Validators} from '@angular/forms';
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
import { ModelHelper } from '@guardian/interfaces';

/**
* Dialog allowing you to select a file and load schemas.
Expand All @@ -15,12 +16,13 @@ export class SetVersionDialog {
Validators.required,
Validators.pattern(/^[\d]+([\\.][\d]+){0,2}$/),
]);
schema: any;

constructor(
public dialogRef: DynamicDialogRef,
public config: DynamicDialogConfig
) {
console.log(3);
this.schema = config.data?.schema;
}

onNoClick(): void {
Expand All @@ -34,6 +36,8 @@ export class SetVersionDialog {
}

get isPublishDisabled(): boolean {
return !this.versionControl.valid;
const isFormInvalid = !this.versionControl.valid;
const isVersionNotNewer = this.schema?.version && ModelHelper.versionCompare(this.schema.version, this.versionControl.value) >= 0;
return isFormInvalid || isVersionNotNewer;
}
}
432 changes: 244 additions & 188 deletions frontend/src/app/views/schemas/schemas.component.html

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions frontend/src/app/views/schemas/schemas.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -754,10 +754,50 @@ a {
}
}

.p-treetable .p-treetable-thead > tr > th {
padding: 0;
}

.guardian-grid-container {

.guardian-grid-header th {
padding: 0.5rem 1rem;
}

::ng-deep .guardian-grid-table {
.p-datatable-wrapper {
max-height: calc(-385px + 100vh);
}

.grey-row.parent {
&:first-child {
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
}

.grey-row {
height: 24px;
background-color: var(--color-grey-white, #FFF);
border-top-left-radius: 8px;
border-top-right-radius: 8px;
&:first-child {
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
&:last-child {
border-top-right-radius: 8px;
}
}

.guardian-grid-row {
background-color: var(--color-grey-white, #FFF);
}

.parent-row-cell {
font-weight: 600;
color: var(--color-grey-black-1);
background-color: var(--color-grey-3, #E1E7EF);
}
}
}
79 changes: 73 additions & 6 deletions frontend/src/app/views/schemas/schemas.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
SchemaHelper,
SchemaStatus,
TagType,
UserPermissions
UserPermissions,
ModelHelper
} from '@guardian/interfaces';
import { forkJoin, Observable, Subject, takeUntil } from 'rxjs';
//services
Expand All @@ -37,6 +38,7 @@ import { ProjectComparisonService } from 'src/app/services/project-comparison.se
import { SchemaDeleteWarningDialogComponent } from 'src/app/modules/schema-engine/schema-delete-warning-dialog/schema-delete-warning-dialog.component';
import { SchemaDeleteDialogComponent } from 'src/app/modules/schema-engine/schema-delete-dialog/schema-delete-dialog.component';
import { ReplaceSchemasDialogComponent } from '../../modules/policy-engine/dialogs/replace-schemas-dialog/replace-schemas-dialog.component';
import { TreeNode } from 'primeng/api';

enum SchemaType {
System = 'system',
Expand Down Expand Up @@ -140,6 +142,7 @@ export class SchemaConfigComponent implements OnInit {
public isAllSelected: boolean = false;
public selectedItems: any[] = [];
public selectedItemIds: string[] = [];
public treeData: TreeNode[] = [];

public onMenuClick(event: MouseEvent, overlayPanel: any, menuData: any): void {
this.element = menuData;
Expand Down Expand Up @@ -332,7 +335,7 @@ export class SchemaConfigComponent implements OnInit {
public ifDraft(element: Schema): boolean {
return (element.status === 'DRAFT' || element.status === 'ERROR');
}

private _destroy$ = new Subject<void>();

ngOnInit() {
Expand Down Expand Up @@ -583,6 +586,7 @@ export class SchemaConfigComponent implements OnInit {
private loadSchemas() {
this.loading = true;
this.page = [];
this.treeData = [];
this.columns = this.getColumns();
this.currentTopic = this.getTopicId();
let loader: Observable<HttpResponse<ISchema[]>>;
Expand All @@ -607,7 +611,7 @@ export class SchemaConfigComponent implements OnInit {
default: {
const category = this.getCategory();
loader = this.schemaService.getSchemasByPage({
category: category,
category,
topicId: this.currentTopic || '',
search: this.textSearch,
pageIndex: this.pageIndex,
Expand All @@ -625,20 +629,80 @@ export class SchemaConfigComponent implements OnInit {
element.__toolName = this.toolNameByTopic[element.topicId] || ' - ';
}
this.count = (schemasResponse.headers.get('X-Total-Count') || this.page.length) as number;
this.treeData = this.groupSchemas(this.page);
this.checkIsAllSelected();
this.loadTagsData();
}, (e) => {
this.loadError(e);
});
}

private groupSchemas(schemas: ISchema[]): TreeNode[] {
if (this.type === SchemaType.System || this.type === SchemaType.Tag) {
return [];
}

const groups = new Map<string, ISchema[]>();
for (const schema of schemas) {
const topicId = schema.topicId || 'no-topic';
if (!groups.has(topicId)) {
groups.set(topicId, []);
}
groups.get(topicId)!.push(schema);
}

const result: TreeNode[] = [];
groups.forEach((groupSchemas, topicId) => {
const sortedSchemas = groupSchemas.sort((a, b) => {
return ModelHelper.versionCompare(b.version || b.sourceVersion || '', a.version || a.sourceVersion || '');
});

let parentName = '';
let parentId = '';
if (this.type === SchemaType.Policy) {
parentName = this.policyNameByTopic[topicId] || '';
parentId = this.policyIdByTopic[topicId];
} else if (this.type === SchemaType.Module) {
parentName = this.moduleNameByTopic[topicId] || '';
} else if (this.type === SchemaType.Tool) {
parentName = this.toolNameByTopic[topicId] || '';
parentId = this.toolIdByTopic[topicId];
}

const parentNode: TreeNode = {
data: {
name: parentName,
topicId,
isParent: true,
policyId: parentId,
toolId: parentId
},
expanded: true,
children: sortedSchemas.map(schema => ({
data: schema,
leaf: true
}))
};
result.push(parentNode);
});

return result;
}

private loadTagsData() {
if (this.type === SchemaType.Policy && this.user.TAGS_TAG_READ) {
const ids = this.page.map(e => String(e.id));
this.tagsService.search(this.tagEntity, ids).subscribe((data) => {
for (const schema of this.page) {
(schema as any)._tags = data[String(schema.id)];
}
for (const node of this.treeData) {
if (node.children) {
for (const child of node.children) {
child.data._tags = data[String(child.data.id)];
}
}
}
setTimeout(() => {
this.loading = false;
}, 500);
Expand Down Expand Up @@ -1215,7 +1279,7 @@ export class SchemaConfigComponent implements OnInit {
delete newDocument.uuid;
delete newDocument.creator;
delete newDocument.owner;
delete newDocument.version;
// delete newDocument.version;
delete newDocument.previousVersion;
const dialogRef = this.dialog.open(CopySchemaDialog, {
width: '860px',
Expand Down Expand Up @@ -1255,6 +1319,9 @@ export class SchemaConfigComponent implements OnInit {
width: '350px',
modal: true,
closable: false,
data: {
schema: element
}
});
dialogRef.onClose.subscribe(async (version) => {
if (version) {
Expand Down Expand Up @@ -1518,12 +1585,12 @@ export class SchemaConfigComponent implements OnInit {
this.user.SCHEMAS_SCHEMA_DELETE
);
}

default:
return true;
}
}

public onSelectAllItems(event: any) {
if (event.checked) {
this.selectedItems = [...this.selectedItems, ...this.page.filter((item: any) => this.ifCanDelete(item) && !this.selectedItemIds.includes(item.id))];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export async function copySchemaAsync(
item.status = SchemaStatus.DRAFT;
item.topicId = topicId;

SchemaHelper.setVersion(item, null, null);
SchemaHelper.setVersion(item, item.version || null, null);
SchemaHelper.updateIRI(item);
item.iri = item.iri || item.uuid;

Expand Down Expand Up @@ -342,7 +342,7 @@ export async function createSchemaAndArtifacts(
newSchema.contextURL = `schema:${newSchema.uuid}`;
}

SchemaHelper.setVersion(newSchema, null, previousVersion);
SchemaHelper.setVersion(newSchema, newSchema.version || null, previousVersion);
const row = await createSchema(newSchema, user, notifier);

if (old) {
Expand Down
Loading