Browse Source

UI: Fixed rule chain note after review

pull/15121/head
Vladyslav_Prykhodko 6 months ago
parent
commit
664aeca930
  1. 4
      ui-ngx/src/app/modules/home/pages/rulechain/add-note-dialog.component.html
  2. 0
      ui-ngx/src/app/modules/home/pages/rulechain/rule-note-editor.component.html
  3. 12
      ui-ngx/src/app/modules/home/pages/rulechain/rule-note-editor.component.ts
  4. 4
      ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.html
  5. 27
      ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts
  6. 4
      ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.module.ts

4
ui-ngx/src/app/modules/home/pages/rulechain/add-note-dialog.component.html

@ -23,8 +23,8 @@
</button> </button>
</mat-toolbar> </mat-toolbar>
<div mat-dialog-content> <div mat-dialog-content>
<tb-rule-note #tbRuleNote [note]="data"> <tb-rule-note-editor #tbRuleNote [note]="data">
</tb-rule-note> </tb-rule-note-editor>
</div> </div>
<div mat-dialog-actions class="flex items-center justify-end"> <div mat-dialog-actions class="flex items-center justify-end">
<button mat-button color="primary" type="button" (click)="cancel()"> <button mat-button color="primary" type="button" (click)="cancel()">

0
ui-ngx/src/app/modules/home/pages/rulechain/rule-note.component.html → ui-ngx/src/app/modules/home/pages/rulechain/rule-note-editor.component.html

12
ui-ngx/src/app/modules/home/pages/rulechain/rule-note.component.ts → ui-ngx/src/app/modules/home/pages/rulechain/rule-note-editor.component.ts

@ -15,15 +15,15 @@
/// ///
import { Component, inject, Input, OnChanges, SimpleChanges } from '@angular/core'; import { Component, inject, Input, OnChanges, SimpleChanges } from '@angular/core';
import { FormBuilder } from '@angular/forms'; import { FormBuilder, Validators } from '@angular/forms';
import { FcRuleNote } from '@shared/models/rule-node.models'; import { FcRuleNote } from '@shared/models/rule-node.models';
@Component({ @Component({
selector: 'tb-rule-note', selector: 'tb-rule-note-editor',
templateUrl: './rule-note.component.html', templateUrl: './rule-note-editor.component.html',
standalone: false standalone: false
}) })
export class RuleNoteComponent implements OnChanges { export class RuleNoteEditorComponent implements OnChanges {
@Input() @Input()
note: FcRuleNote; note: FcRuleNote;
@ -31,10 +31,10 @@ export class RuleNoteComponent implements OnChanges {
private fb = inject(FormBuilder) private fb = inject(FormBuilder)
noteForm = this.fb.group({ noteForm = this.fb.group({
content: [''], content: ['', Validators.maxLength(65536)],
backgroundColor: ['#FFF9C4'], backgroundColor: ['#FFF9C4'],
applyDefaultMarkdownStyle: [true], applyDefaultMarkdownStyle: [true],
markdownCss: [''] markdownCss: ['', Validators.maxLength(65536)]
}); });
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {

4
ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.html

@ -167,10 +167,10 @@
(toggleDetailsEditMode)="onRevertNoteEdit()" (toggleDetailsEditMode)="onRevertNoteEdit()"
(applyDetails)="saveNote()" (applyDetails)="saveNote()"
[theForm]="tbRuleNote.noteForm"> [theForm]="tbRuleNote.noteForm">
<tb-rule-note #tbRuleNote <tb-rule-note-editor #tbRuleNote
[note]="editingNote" [note]="editingNote"
class="flex-1"> class="flex-1">
</tb-rule-note> </tb-rule-note-editor>
</tb-details-panel> </tb-details-panel>
</mat-drawer> </mat-drawer>
<mat-drawer-content class="tb-rulechain-graph-content"> <mat-drawer-content class="tb-rulechain-graph-content">

27
ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts

@ -81,10 +81,10 @@ import { RuleChainService } from '@core/http/rule-chain.service';
import { NEVER, Observable, of, ReplaySubject, skip, startWith, Subject, throwError } from 'rxjs'; import { NEVER, Observable, of, ReplaySubject, skip, startWith, Subject, throwError } from 'rxjs';
import { catchError, debounceTime, distinctUntilChanged, mergeMap, takeUntil, tap } from 'rxjs/operators'; import { catchError, debounceTime, distinctUntilChanged, mergeMap, takeUntil, tap } from 'rxjs/operators';
import { ISearchableComponent } from '../../models/searchable-component.models'; import { ISearchableComponent } from '../../models/searchable-component.models';
import { deepClone, isDefinedAndNotNull } from '@core/utils'; import { deepClone, guid, isDefinedAndNotNull } from '@core/utils';
import { RuleNodeDetailsComponent } from '@home/pages/rulechain/rule-node-details.component'; import { RuleNodeDetailsComponent } from '@home/pages/rulechain/rule-node-details.component';
import { RuleNodeLinkComponent } from './rule-node-link.component'; import { RuleNodeLinkComponent } from './rule-node-link.component';
import { RuleNoteComponent } from './rule-note.component'; import { RuleNoteEditorComponent } from './rule-note-editor.component';
import { DialogComponent } from '@shared/components/dialog.component'; import { DialogComponent } from '@shared/components/dialog.component';
import { MatMenuTrigger } from '@angular/material/menu'; import { MatMenuTrigger } from '@angular/material/menu';
import { ItemBufferService, RuleNodeConnection } from '@core/services/item-buffer.service'; import { ItemBufferService, RuleNodeConnection } from '@core/services/item-buffer.service';
@ -162,7 +162,7 @@ export class RuleChainPageComponent extends PageComponent
@ViewChild('tbRuleNode') ruleNodeComponent: RuleNodeDetailsComponent; @ViewChild('tbRuleNode') ruleNodeComponent: RuleNodeDetailsComponent;
@ViewChild('tbRuleNodeLink') ruleNodeLinkComponent: RuleNodeLinkComponent; @ViewChild('tbRuleNodeLink') ruleNodeLinkComponent: RuleNodeLinkComponent;
@ViewChild('tbRuleNote') ruleNoteComponent: RuleNoteComponent; @ViewChild('tbRuleNote') ruleNoteComponent: RuleNoteEditorComponent;
editingRuleNodeLink: FcRuleEdge = null; editingRuleNodeLink: FcRuleEdge = null;
isEditingRuleNodeLink = false; isEditingRuleNodeLink = false;
@ -170,7 +170,7 @@ export class RuleChainPageComponent extends PageComponent
editingNote: FcRuleNote = null; editingNote: FcRuleNote = null;
isEditingNote = false; isEditingNote = false;
editingNoteIndex = -1; editingNoteId: string = null;
hotKeys: Hotkey[] = []; hotKeys: Hotkey[] = [];
@ -1306,7 +1306,7 @@ export class RuleChainPageComponent extends PageComponent
this.ruleChainModel.notes = []; this.ruleChainModel.notes = [];
} }
ruleChainObjects.notes.forEach((note) => { ruleChainObjects.notes.forEach((note) => {
note.id = 'rule-chain-note-' + Date.now(); note.id = guid();
this.ruleChainModel.notes.push(note); this.ruleChainModel.notes.push(note);
this.ruleChainCanvas.modelService.notes.select(note); this.ruleChainCanvas.modelService.notes.select(note);
}); });
@ -1343,7 +1343,7 @@ export class RuleChainPageComponent extends PageComponent
y = scrollParent.scrollTop() + scrollParent.height() / 2; y = scrollParent.scrollTop() + scrollParent.height() / 2;
} }
const note: FcRuleNote = { const note: FcRuleNote = {
id: 'rule-chain-note-' + Date.now(), id: guid(),
x, x,
y, y,
width: 200, width: 200,
@ -1364,7 +1364,10 @@ export class RuleChainPageComponent extends PageComponent
headerClass: 'tb-rulechain-header', headerClass: 'tb-rulechain-header',
icon: 'sticky_note_2', icon: 'sticky_note_2',
title: this.translate.instant('rulechain.note'), title: this.translate.instant('rulechain.note'),
subtitle: note.content.length > 24 ? note.content.substring(0, 24) + '…' : note.content, subtitle: (() => {
const plain = (note.content || '').replace(/[#*_`>\[\]!\\~]/g, '').trim();
return plain.length > 24 ? plain.substring(0, 24) + '…' : plain;
})(),
menuItems: [] menuItems: []
}; };
if (!note.readonly) { if (!note.readonly) {
@ -1411,14 +1414,15 @@ export class RuleChainPageComponent extends PageComponent
this.isEditingRuleNodeLink = false; this.isEditingRuleNodeLink = false;
this.editingRuleNodeLink = null; this.editingRuleNodeLink = null;
this.isEditingNote = true; this.isEditingNote = true;
this.editingNoteIndex = this.ruleChainModel.notes.indexOf(note); this.editingNoteId = note.id;
this.editingNote = deepClone(note); this.editingNote = deepClone(note);
} }
saveNote(): void { saveNote(): void {
this.ruleNoteComponent.noteForm.markAsPristine(); this.ruleNoteComponent.noteForm.markAsPristine();
Object.assign(this.editingNote, this.ruleNoteComponent.noteForm.value); Object.assign(this.editingNote, this.ruleNoteComponent.noteForm.value);
this.ruleChainModel.notes[this.editingNoteIndex] = this.editingNote; const idx = this.ruleChainModel.notes.findIndex(n => n.id === this.editingNoteId);
this.ruleChainModel.notes[idx] = this.editingNote;
this.editingNote = deepClone(this.editingNote); this.editingNote = deepClone(this.editingNote);
this.isDirty = true; this.isDirty = true;
this.onModelChanged(); this.onModelChanged();
@ -1426,13 +1430,14 @@ export class RuleChainPageComponent extends PageComponent
onRevertNoteEdit(): void { onRevertNoteEdit(): void {
this.ruleNoteComponent.noteForm.markAsPristine(); this.ruleNoteComponent.noteForm.markAsPristine();
const note = this.ruleChainModel.notes[this.editingNoteIndex]; const note = this.ruleChainModel.notes.find(n => n.id === this.editingNoteId);
this.editingNote = deepClone(note); this.editingNote = deepClone(note);
} }
onEditNoteClosed(): void { onEditNoteClosed(): void {
this.editingNote = null; this.editingNote = null;
this.isEditingNote = false; this.isEditingNote = false;
this.editingNoteId = null;
} }
onDetailsDrawerClosed() { onDetailsDrawerClosed() {
@ -2165,7 +2170,7 @@ export class CreateNestedRuleChainDialogComponent extends DialogComponent<Create
}) })
export class AddNoteDialogComponent extends DialogComponent<AddNoteDialogComponent, Partial<FcRuleNote>> { export class AddNoteDialogComponent extends DialogComponent<AddNoteDialogComponent, Partial<FcRuleNote>> {
@ViewChild('tbRuleNote') ruleNoteComponent: RuleNoteComponent; @ViewChild('tbRuleNote') ruleNoteComponent: RuleNoteEditorComponent;
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
protected router: Router, protected router: Router,

4
ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.module.ts

@ -34,13 +34,13 @@ import { RuleNodeDetailsComponent } from '@home/pages/rulechain/rule-node-detail
import { RuleNodeConfigComponent } from '@home/pages/rulechain/rule-node-config.component'; import { RuleNodeConfigComponent } from '@home/pages/rulechain/rule-node-config.component';
import { LinkLabelsComponent } from '@home/pages/rulechain/link-labels.component'; import { LinkLabelsComponent } from '@home/pages/rulechain/link-labels.component';
import { RuleNodeLinkComponent } from '@home/pages/rulechain/rule-node-link.component'; import { RuleNodeLinkComponent } from '@home/pages/rulechain/rule-node-link.component';
import { RuleNoteComponent } from '@home/pages/rulechain/rule-note.component'; import { RuleNoteEditorComponent } from '@home/pages/rulechain/rule-note-editor.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
RuleChainPageComponent, RuleChainPageComponent,
RuleNodeDetailsComponent, RuleNodeDetailsComponent,
RuleNoteComponent, RuleNoteEditorComponent,
LinkLabelsComponent, LinkLabelsComponent,
RuleNodeLinkComponent, RuleNodeLinkComponent,
RuleNodeConfigComponent, RuleNodeConfigComponent,

Loading…
Cancel
Save