Skip to content

Commit

Permalink
XMLUploadComponent: Reformat (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
denysvitali committed Mar 20, 2019
1 parent 377a152 commit f18410a
Showing 1 changed file with 48 additions and 42 deletions.
90 changes: 48 additions & 42 deletions src/app/shared/components/xmlupload/xmlupload.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ import { Component } from "@angular/core";
import { HtmlParser } from "@angular/compiler";
import { parse } from "url";

import {Body, Document, Segment, Header, File} from 'Models/document/document';
import {
Body,
Document,
Segment,
Header,
File
} from "Models/document/document";

function createSegment(features: string[], id: number, state: string) {
let newSegment = { features : [""] , id: -1, state : "active"};
let newSegment = { features: [""], id: -1, state: "active" };
if (features) {
newSegment.features = features;
}
if(id){
if (id) {
newSegment.id = id;
}
if(state){
if (state) {
newSegment.state = state;
}
return newSegment;
Expand All @@ -24,7 +30,7 @@ function createSegment(features: string[], id: number, state: string) {
styleUrls: ["./xmlupload.component.scss"]
})
export class XmlUploadComponent {
private debug : boolean = true;
private debug: boolean = true;
ngOnInit(): void {}

load(files: FileList) {
Expand All @@ -41,63 +47,63 @@ export class XmlUploadComponent {
fileReader.result.toString(),
"text/xml"
);
let segmentsArray : Array<HTMLElement> = Array.prototype.map.call(

let segmentsArray: Array<HTMLElement> = Array.prototype.map.call(
parser.querySelector("body").childNodes,
(a: Node, i : Number) => {
(a: Node, i: Number) => {
if (a.nodeType === Node.TEXT_NODE) {
let d = document.createElement("segment");
d.innerHTML = a.textContent;
a = d;
let d = document.createElement("segment");
d.innerHTML = a.textContent;
a = d;
}
(<HTMLElement> a).setAttribute("id", i.toString());

(<HTMLElement>a).setAttribute("id", i.toString());
return a;
}
);
if(this.debug){
console.log(segmentsArray[0].textContent.split('\n'));

if (this.debug) {
console.log(segmentsArray[0].textContent.split("\n"));
console.log(segmentsArray);
}

let segs : Segment[] = [];
for(let i in segmentsArray){
let features_str : string;
let segs: Segment[] = [];
for (let i in segmentsArray) {
let features_str: string;
features_str = segmentsArray[i].getAttribute("features");
let features : string[];
if(features_str)
features = features_str.split(";");
segs.push(createSegment(
features,
parseInt(segmentsArray[i].getAttribute("id")),
"active"
));
let features: string[];
if (features_str) features = features_str.split(";");
segs.push(
createSegment(
features,
parseInt(segmentsArray[i].getAttribute("id")),
"active"
)
);
}

if(this.debug){
for(let i in segs){
console.log(i, "\t ", segs[i].features);
if (this.debug) {
for (let i in segs) {
console.log(i, "\t ", segs[i].features);
}
}

let headerArray = parser.querySelector("header").children;
let head : Header = {
textfile : headerArray[0].textContent,
lang : headerArray[1].textContent
let head: Header = {
textfile: headerArray[0].textContent,
lang: headerArray[1].textContent
};

let bod : Body = {
segments : segs
}
let bod: Body = {
segments: segs
};

let doc : Document = {
header : head,
body : bod
}
let doc: Document = {
header: head,
body: bod
};

let file : File = new File(1, doc);
let file: File = new File(1, doc);
};

}
}

0 comments on commit f18410a

Please sign in to comment.