54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const immutable_1 = __importDefault(require("immutable"));
|
|
const summaryArticle_1 = __importDefault(require("./summaryArticle"));
|
|
class SummaryPart extends immutable_1.default.Record({
|
|
level: String(),
|
|
title: String(),
|
|
articles: immutable_1.default.List()
|
|
}) {
|
|
getLevel() {
|
|
return this.get("level");
|
|
}
|
|
getTitle() {
|
|
return this.get("title");
|
|
}
|
|
getArticles() {
|
|
return this.get("articles");
|
|
}
|
|
/**
|
|
* Create a new level for a new child article
|
|
*
|
|
* @return {string}
|
|
*/
|
|
createChildLevel() {
|
|
const level = this.getLevel();
|
|
const subArticles = this.getArticles();
|
|
const childLevel = `${level}.${subArticles.size + 1}`;
|
|
return childLevel;
|
|
}
|
|
/**
|
|
* Create a SummaryPart
|
|
*
|
|
* @param {Object} def
|
|
* @return {SummaryPart}
|
|
*/
|
|
static create(def, level) {
|
|
const articles = (def.articles || []).map((article, i) => {
|
|
if (article instanceof summaryArticle_1.default) {
|
|
return article;
|
|
}
|
|
return summaryArticle_1.default.create(article, [level, i + 1].join("."));
|
|
});
|
|
return new SummaryPart({
|
|
level: String(level),
|
|
title: def.title,
|
|
articles: immutable_1.default.List(articles)
|
|
});
|
|
}
|
|
}
|
|
exports.default = SummaryPart;
|