@webuildbots/webuildbots-sdk
Version:
webuildbots sdk
80 lines (79 loc) • 2.77 kB
JavaScript
"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var deep_equal_1 = __importDefault(require("deep-equal"));
var ItemBuilder = /** @class */ (function () {
function ItemBuilder() {
this.item = {
choices: []
};
}
ItemBuilder.prototype.addTitle = function (lang, text) {
this.item.title = this.item.title || {};
this.item.title[lang] = text;
return this;
};
ItemBuilder.prototype.setTitle = function (polylang) {
this.item.title = polylang;
return this;
};
ItemBuilder.prototype.addSubtitle = function (lang, text) {
this.item.subtitle = this.item.subtitle || {};
this.item.subtitle[lang] = text;
return this;
};
ItemBuilder.prototype.setSubtitle = function (polylang) {
this.item.subtitle = polylang;
return this;
};
/**
* This function will only take string as an argument which can be ObjectId or URL
* @param media : string
* @returns
*/
ItemBuilder.prototype.image = function (media) {
this.item.image = media;
return this;
};
ItemBuilder.prototype.build = function () {
return this.item;
};
ItemBuilder.prototype.pushChoice = function (cb) {
this.item.choices.push(cb.build());
return this;
};
ItemBuilder.prototype.unshiftChoice = function (cb) {
this.item.choices.unshift(cb.build());
return this;
};
ItemBuilder.prototype.setChoices = function (choices) {
this.item.choices = choices.map(function (cb) { return cb.build(); });
return this;
};
ItemBuilder.prototype.defaultChoice = function (cb) {
this.item.defaultChoice = cb.build();
return this;
};
ItemBuilder.prototype.hasChoice = function (cb) {
var myChoice = cb.build();
var choices = __spreadArray([], this.item.choices, true);
var defaultChoice = this.item.defaultChoice;
if (defaultChoice) {
choices.push(defaultChoice);
}
return choices.some(function (choice) { return (0, deep_equal_1.default)(choice, myChoice); });
};
return ItemBuilder;
}());
exports.default = ItemBuilder;