diff --git a/src/app/shared/components/tag/tag.component.test.ts b/src/app/shared/components/tag/tag.component.test.ts index e4f7abc..d9b69fb 100644 --- a/src/app/shared/components/tag/tag.component.test.ts +++ b/src/app/shared/components/tag/tag.component.test.ts @@ -1,9 +1,8 @@ import { TagComponent } from "./tag.component"; import { ElementRef } from "@angular/core"; - test("setContent", () => { - let tag : TagComponent = new TagComponent(); + let tag : TagComponent = new TagComponent(null); let content = document.createElement("p"); tag.content = new ElementRef(document.createElement("div")); content.innerHTML = "test node"; @@ -13,17 +12,4 @@ test("setContent", () => { content.innerHTML = "test 2"; expect(natEl.children[0]).toBe(content); expect(natEl.children[0].innerHTML).toBe(content.innerHTML); -}); - -/* -test("setType", () => { - let tag : TagComponent = new TagComponent(); - let inner = document.createElement("p"); - tag.tag = new ElementRef(document.createElement("div")); - let natEl : HTMLElement = tag.tag.nativeElement; - tag.setType(1); - expect(natEl.style.backgroundColor).toBe("rgb(216, 27, 96)"); // #D81B60 Hex -> 216, 27, 96 RGB - tag.setType(2); - expect(natEl.style.backgroundColor).toBe("rgb(251, 140, 0)"); // #FB8C00 Hex -> 251, 140, 0 RGB -}); -*/ \ No newline at end of file +}); \ No newline at end of file diff --git a/src/app/shared/components/tag/tag.component.ts b/src/app/shared/components/tag/tag.component.ts index fab451e..8efa719 100644 --- a/src/app/shared/components/tag/tag.component.ts +++ b/src/app/shared/components/tag/tag.component.ts @@ -3,6 +3,7 @@ import { HSLColor } from "Models/hslcolor/HSLColor"; import { ColorizedNode } from "Models/tree/ColorizedTree"; import { CustomTextareaComponent } from "Components/textedit/components/customtextarea.component"; import { Document } from "Models/document/document"; +import { DocumentService } from "Services/document/DocumentService"; @Component({ selector: "doctt-tag", @@ -19,7 +20,7 @@ export class TagComponent implements OnInit { @ViewChild("tag") tag: ElementRef | undefined; @ViewChild("tagInner") content: ElementRef | undefined; - constructor() { } + constructor(private documentService : DocumentService) { } ngOnInit(): void { } @@ -75,7 +76,8 @@ export class TagComponent implements OnInit { } let id = Number.parseInt(spanContainer.getAttribute("data-segment-id")); - CustomTextareaComponent.removeFeaturesBySegmentId(this.document, id); + //CustomTextareaComponent.removeFeaturesBySegmentId(this.document, id); + CustomTextareaComponent.removeFeaturesFromSegmentID(id, this.documentService, this.document); if(father != null){ father.insertBefore(docFragment, spanContainer); diff --git a/src/app/shared/components/textedit/components/customtextarea.component.ts b/src/app/shared/components/textedit/components/customtextarea.component.ts index 7d2dedd..4c0d420 100644 --- a/src/app/shared/components/textedit/components/customtextarea.component.ts +++ b/src/app/shared/components/textedit/components/customtextarea.component.ts @@ -374,12 +374,36 @@ export class CustomTextareaComponent implements OnInit { return true; } + public static removeFeaturesFromSegmentID(id : number, documentService : DocumentService, document : Document){ + let docs : Document[] = documentService.loadDocuments(); + document.body.segments = this.recursiveFeatuersRemoval(document.body.segments, id); + docs[document.header.id] = document; + documentService.storeDocuments(docs); + } + + private static recursiveFeatuersRemoval(segments : Segment[], id : number) : Segment[]{ + if(segments.length == 0){ + return []; + } + + for(let s of segments){ + if(s.id == id){ + s.features = []; + return segments; + } + if(s.children != null && s.children != []){ + s.children = this.recursiveFeatuersRemoval(s.children, id); + } + } + return segments; + } + /* public static removeFeaturesBySegmentId(document: Document, id: number){ let s = this.findSegmentById(document.body.segments, id); s.features = []; this.replaceSegmentInDocument(document, s, id); } - + */ private static findSegmentById(segments: Segment[], id : number) : Segment { if(segments.length == 0){ return null; @@ -593,7 +617,7 @@ export class CustomTextareaComponent implements OnInit { let tag = this.findTagByFeatures(ct, s.features); if (tag == null) { - console.error("Invalid tag!"); + console.info("Features null!"); content.setAttribute("data-segment-id", s.id.toString()); el.appendChild(content); return; @@ -604,6 +628,7 @@ export class CustomTextareaComponent implements OnInit { let element: ComponentRef = ref; element.instance.setContent(content); element.instance.setTag(tag); + element.instance.setDocument(this.document); el.appendChild(divSegment); }