grunt clean
This commit is contained in:
Родитель
b8ba318c56
Коммит
eeabe6a3a4
|
@ -1,35 +0,0 @@
|
|||
define(["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
var ErrorContainer = (function () {
|
||||
function ErrorContainer(parser, model) {
|
||||
this._errors = [];
|
||||
this._errorsInputParser = [];
|
||||
this._errorsModel = [];
|
||||
this._parser = parser;
|
||||
this._model = model;
|
||||
}
|
||||
ErrorContainer.prototype.hasErrors = function () {
|
||||
this._errorsInputParser = this._parser.getErrors();
|
||||
this._errorsModel = this._model.getErrors();
|
||||
if (this._errorsInputParser || this._errorsModel)
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
ErrorContainer.prototype.getErrors = function () {
|
||||
for (var _i = 0, _a = this._errorsInputParser; _i < _a.length; _i++) {
|
||||
var error = _a[_i];
|
||||
this._errors.push(error);
|
||||
}
|
||||
for (var _b = 0, _c = this._errorsModel; _b < _c.length; _b++) {
|
||||
var error = _c[_b];
|
||||
this._errors.push(error);
|
||||
}
|
||||
return this._errors;
|
||||
};
|
||||
ErrorContainer.prototype.push = function (error) {
|
||||
this._errors.push(error);
|
||||
};
|
||||
return ErrorContainer;
|
||||
}());
|
||||
exports.ErrorContainer = ErrorContainer;
|
||||
});
|
|
@ -1,3 +0,0 @@
|
|||
define(["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
});
|
|
@ -1,63 +0,0 @@
|
|||
define(["require", "exports", "./colors"], function (require, exports, colors_1) {
|
||||
"use strict";
|
||||
var InputParser = (function () {
|
||||
function InputParser() {
|
||||
}
|
||||
InputParser.getFieldName = function (inputs) {
|
||||
if (inputs["FieldName"]) {
|
||||
return inputs["FieldName"];
|
||||
}
|
||||
throw ("FieldName not specified.");
|
||||
};
|
||||
InputParser.getOptions = function (inputs, allowedValues) {
|
||||
if (allowedValues && allowedValues.length) {
|
||||
var colors = [];
|
||||
var inputColors = [];
|
||||
var labels = [];
|
||||
var inputLabels = [];
|
||||
inputColors = InputParser.extractInputs(inputs["Colors"]);
|
||||
inputLabels = InputParser.extractInputs(inputs["Labels"]);
|
||||
colors = InputParser.getColors(inputColors, allowedValues);
|
||||
labels = InputParser.getLabels(inputLabels, allowedValues);
|
||||
return InputParser.buildOptions(allowedValues, colors, labels);
|
||||
}
|
||||
else {
|
||||
throw ("Allowed values not specified.");
|
||||
}
|
||||
};
|
||||
InputParser.extractInputs = function (rawInput) {
|
||||
if (rawInput) {
|
||||
return rawInput.split(";");
|
||||
}
|
||||
return [];
|
||||
};
|
||||
InputParser.getColors = function (inputColors, values) {
|
||||
if (values.length > inputColors.length && inputColors.length !== 0) {
|
||||
throw ("Not enough colors provided in admin XML file.");
|
||||
}
|
||||
if (inputColors.length === 0) {
|
||||
return colors_1.Colors.getColors(values.length);
|
||||
}
|
||||
else {
|
||||
return values.map(function (v, idx) { return inputColors[idx] || ""; });
|
||||
}
|
||||
};
|
||||
InputParser.getLabels = function (inputLabels, values) {
|
||||
return values.map(function (v, idx) { return inputLabels[idx] || ""; });
|
||||
};
|
||||
InputParser.buildOptions = function (values, colors, labels) {
|
||||
var options = [];
|
||||
var valuesLength = values.length;
|
||||
for (var i = 0; i < valuesLength; i++) {
|
||||
options.push({
|
||||
value: values[i],
|
||||
color: colors[i],
|
||||
label: labels[i]
|
||||
});
|
||||
}
|
||||
return options;
|
||||
};
|
||||
return InputParser;
|
||||
}());
|
||||
exports.InputParser = InputParser;
|
||||
});
|
|
@ -1,60 +0,0 @@
|
|||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
define(["require", "exports", 'chai', "./InputParser"], function (require, exports, chai_1, InputParser_1) {
|
||||
"use strict";
|
||||
var TestableInputParser = (function (_super) {
|
||||
__extends(TestableInputParser, _super);
|
||||
function TestableInputParser() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
TestableInputParser.prototype.testableExtractInputs = function (customInputs) {
|
||||
var inputs = customInputs;
|
||||
this._extractFieldName(inputs);
|
||||
this._values = this._parseInput(inputs["Values"]);
|
||||
this._colors = this._parseInput(inputs["Colors"]);
|
||||
this._labels = this._parseInput(inputs["Labels"]);
|
||||
};
|
||||
return TestableInputParser;
|
||||
}(InputParser_1.InputParser));
|
||||
describe("inputParser", function () {
|
||||
var inputParser;
|
||||
beforeEach(function () {
|
||||
inputParser = new TestableInputParser();
|
||||
});
|
||||
inputParser.testableExtractInputs({ "FieldName": "Priority",
|
||||
"Colors": "red;orange;yellow;blue",
|
||||
"Values": "0;1;2;3",
|
||||
"Labels": "Critical;High;Medium;Low" });
|
||||
it("outputs number when not divisible by 3 or 5", function () {
|
||||
chai_1.expect(inputParser.getParsedFieldName()).to.be.equal("Priority");
|
||||
chai_1.expect(inputParser.getParsedColors()).to.be.equal(["red", "orange", "yellow", "blue"]);
|
||||
chai_1.expect(inputParser.getParsedValues()).to.be.equal(["0", "1", "2", "3"]);
|
||||
chai_1.expect(inputParser.getParsedLabels()).to.be.equal(["Critical", "High", "Medium", "Low"]);
|
||||
chai_1.expect(inputParser.getErrors()).to.be.equal([]);
|
||||
});
|
||||
inputParser.testableExtractInputs({ "FieldName": "",
|
||||
"Colors": "red;orange;yellow;blue",
|
||||
"Values": "0;1;2;3",
|
||||
"Labels": "Critical;High;Medium;Low" });
|
||||
it("outputs number when not divisible by 3 or 5", function () {
|
||||
chai_1.expect(inputParser.getParsedFieldName()).to.be.equal("Priority");
|
||||
chai_1.expect(inputParser.getParsedColors()).to.be.equal(["red", "orange", "yellow", "blue"]);
|
||||
chai_1.expect(inputParser.getParsedValues()).to.be.equal(["0", "1", "2", "3"]);
|
||||
chai_1.expect(inputParser.getParsedLabels()).to.be.equal(["FieldName not found"]);
|
||||
});
|
||||
inputParser.testableExtractInputs({ "FieldName": "",
|
||||
"Colors": ";;;",
|
||||
"Values": ";;;",
|
||||
"Labels": ";;;" });
|
||||
it("Checks if error with empty string", function () {
|
||||
chai_1.expect(inputParser.getParsedFieldName()).to.be.equal("");
|
||||
chai_1.expect(inputParser.getParsedColors()).to.be.equal(["", "", "", ""]);
|
||||
chai_1.expect(inputParser.getParsedValues()).to.be.equal(["", "", ""]);
|
||||
chai_1.expect(inputParser.getParsedLabels()).to.be.equal(["", "", "", ""]);
|
||||
chai_1.expect(inputParser.getParsedLabels()).to.be.equal(["FieldName not found"]);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,146 +0,0 @@
|
|||
define(["require", "exports", 'chai', "./InputParser"], function (require, exports, chai_1, InputParser_1) {
|
||||
"use strict";
|
||||
describe("InputParser", function () {
|
||||
var bestCaseDict = {
|
||||
"FieldName": "Priority",
|
||||
"Colors": "red;orange;yellow;blue",
|
||||
"Values": "0;1;2;3",
|
||||
"Labels": "Critical;High;Medium;Low"
|
||||
};
|
||||
var bestCaseValues = ["1", "2", "3", "4"];
|
||||
it("gets the field name specified in dictionary", function () {
|
||||
chai_1.expect(InputParser_1.InputParser.getFieldName(bestCaseDict)).to.be.deep.equal("Priority");
|
||||
});
|
||||
it("throws when field name not specified", function () {
|
||||
chai_1.expect(function () { return InputParser_1.InputParser.getFieldName({
|
||||
"FieldName": ""
|
||||
}); }).throw("FieldName not specified.");
|
||||
});
|
||||
it("returns an array of interfaces", function () {
|
||||
chai_1.expect(InputParser_1.InputParser.getOptions(bestCaseDict, bestCaseValues)).to.be.deep.equal([
|
||||
{ value: "1", color: "red", label: "Critical" },
|
||||
{ value: "2", color: "orange", label: "High" },
|
||||
{ value: "3", color: "yellow", label: "Medium" },
|
||||
{ value: "4", color: "blue", label: "Low" }]);
|
||||
});
|
||||
it("returns options with empty strings in label key when no labels are provided", function () {
|
||||
chai_1.expect(InputParser_1.InputParser.getOptions({
|
||||
"FieldName": "Priority",
|
||||
"Colors": "red;orange;yellow;blue",
|
||||
"Values": "1;2;3;4",
|
||||
"Labels": ""
|
||||
}, bestCaseValues)).to.be.deep.equal([
|
||||
{ value: "1", color: "red", label: "" },
|
||||
{ value: "2", color: "orange", label: "" },
|
||||
{ value: "3", color: "yellow", label: "" },
|
||||
{ value: "4", color: "blue", label: "" }]);
|
||||
});
|
||||
it("returns 1 default color when 1 value and no colors are provided", function () {
|
||||
chai_1.expect(InputParser_1.InputParser.getOptions({
|
||||
"FieldName": "Priority",
|
||||
"Colors": "",
|
||||
"Values": "1",
|
||||
"Labels": "Critical"
|
||||
}, ["1"])).to.be.deep.equal([
|
||||
{ value: "1", color: "red", label: "Critical" }]);
|
||||
});
|
||||
it("returns options with default colors and NO labels when NO colors and NO labels provided.", function () {
|
||||
chai_1.expect(InputParser_1.InputParser.getOptions({
|
||||
"FieldName": "Priority",
|
||||
"Colors": "",
|
||||
"Values": "1;2;3;4",
|
||||
"Labels": ""
|
||||
}, ["1", "2", "3", "4"])).to.be.deep.equal([
|
||||
{ value: "1", color: "red", label: "" },
|
||||
{ value: "2", color: "orange", label: "" },
|
||||
{ value: "3", color: "yellow", label: "" },
|
||||
{ value: "4", color: "blue", label: "" }]);
|
||||
});
|
||||
it("throws when allowed values are not specified", function () {
|
||||
chai_1.expect(function () { return InputParser_1.InputParser.getOptions({
|
||||
"FieldName": "Priority",
|
||||
"Colors": "red;orange;yellow;blue",
|
||||
"Values": "",
|
||||
"Labels": "Critical;High;Medium"
|
||||
}, []); }).throw("Allowed values not specified.");
|
||||
});
|
||||
it("Returns options with some empty labels if less labels than values provided", function () {
|
||||
chai_1.expect(InputParser_1.InputParser.getOptions({
|
||||
"FieldName": "Priority",
|
||||
"Colors": "red;orange;yellow;blue",
|
||||
"Values": "1;2;3;4",
|
||||
"Labels": "Critical;High;Medium"
|
||||
}, ["1", "2", "3", "4"])).to.be.deep.equal([
|
||||
{ value: "1", color: "red", label: "Critical" },
|
||||
{ value: "2", color: "orange", label: "High" },
|
||||
{ value: "3", color: "yellow", label: "Medium" },
|
||||
{ value: "4", color: "blue", label: "" }]);
|
||||
});
|
||||
it("throws when less colors than values are provided", function () {
|
||||
chai_1.expect(function () { return InputParser_1.InputParser.getOptions({
|
||||
"FieldName": "Priority",
|
||||
"Colors": "red;orange",
|
||||
"Values": "1;2;3;4",
|
||||
"Labels": "Critical;High;Medium;Low"
|
||||
}, ["1", "2", "3", "4"]); }).throw("Not enough colors provided in admin XML file.");
|
||||
});
|
||||
it("gives one label to every value, and truncates unused labels when MORE Labels THAN values are provided", function () {
|
||||
chai_1.expect(InputParser_1.InputParser.getOptions({
|
||||
"FieldName": "Priority",
|
||||
"Colors": "red;orange;yellow;blue",
|
||||
"Values": "1;2;3;4",
|
||||
"Labels": "Critical;High;Medium;Low;Very Low"
|
||||
}, ["1", "2", "3", "4"])).to.be.deep.equal([
|
||||
{ value: "1", color: "red", label: "Critical" },
|
||||
{ value: "2", color: "orange", label: "High" },
|
||||
{ value: "3", color: "yellow", label: "Medium" },
|
||||
{ value: "4", color: "blue", label: "Low" }]);
|
||||
});
|
||||
it("gives one color to every value, and truncates unused colors when MORE colors THAN values are provided", function () {
|
||||
chai_1.expect(InputParser_1.InputParser.getOptions({
|
||||
"FieldName": "Priority",
|
||||
"Colors": "red;orange;yellow;blue;magenta;deep-blue",
|
||||
"Values": "1;2;3;4",
|
||||
"Labels": "Critical;High;Medium;Low;Very Low"
|
||||
}, ["1", "2", "3", "4"])).to.be.deep.equal([
|
||||
{ value: "1", color: "red", label: "Critical" },
|
||||
{ value: "2", color: "orange", label: "High" },
|
||||
{ value: "3", color: "yellow", label: "Medium" },
|
||||
{ value: "4", color: "blue", label: "Low" }]);
|
||||
});
|
||||
it("returns custom positions of labels when label is placed between semicolons.", function () {
|
||||
chai_1.expect(InputParser_1.InputParser.getOptions({
|
||||
"FieldName": "Priority",
|
||||
"Colors": "red;orange;yellow;blue",
|
||||
"Values": "1;2;3;4",
|
||||
"Labels": "Critical;;;Low"
|
||||
}, ["1", "2", "3", "4"])).to.be.deep.equal([
|
||||
{ value: "1", color: "red", label: "Critical" },
|
||||
{ value: "2", color: "orange", label: "" },
|
||||
{ value: "3", color: "yellow", label: "" },
|
||||
{ value: "4", color: "blue", label: "Low" }]);
|
||||
});
|
||||
it("returns custom positions of colors when no color is placed between semicolons.", function () {
|
||||
chai_1.expect(InputParser_1.InputParser.getOptions({
|
||||
"FieldName": "Priority",
|
||||
"Colors": "red;;yellow;blue",
|
||||
"Values": "1;2;3;4",
|
||||
"Labels": "Critical;High;Medium;Low"
|
||||
}, ["1", "2", "3", "4"])).to.be.deep.equal([
|
||||
{ value: "1", color: "red", label: "Critical" },
|
||||
{ value: "2", color: "", label: "High" },
|
||||
{ value: "3", color: "yellow", label: "Medium" },
|
||||
{ value: "4", color: "blue", label: "Low" }]);
|
||||
});
|
||||
it("Returns one option when one value,one label, and one are color provided", function () {
|
||||
chai_1.expect(InputParser_1.InputParser.getOptions({
|
||||
"FieldName": "Priority",
|
||||
"Colors": "red",
|
||||
"Values": "1",
|
||||
"Labels": "Critical"
|
||||
}, ["1"])).to.be.deep.equal([
|
||||
{ value: "1", color: "red", label: "Critical" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,35 +0,0 @@
|
|||
define(["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
var Colors = (function () {
|
||||
function Colors() {
|
||||
}
|
||||
Colors.getColors = function (numberOfValues) {
|
||||
var newColors = [];
|
||||
var defaultColors = [
|
||||
["red"],
|
||||
["red", "blue"],
|
||||
["red", "yellow", "blue"],
|
||||
["red", "orange", "yellow", "blue"],
|
||||
["red", "orange", "yellow", "blue", "dark blue"],
|
||||
["dark red", "red", "orange", "yellow", "blue", "dark blue"],
|
||||
["dark red", "red", "orange", "yellow", "blue", "dark blue", "purple"]
|
||||
];
|
||||
if (numberOfValues > 0 && numberOfValues <= defaultColors.length) {
|
||||
newColors = defaultColors[numberOfValues - 1];
|
||||
return newColors;
|
||||
}
|
||||
else if (numberOfValues > defaultColors.length) {
|
||||
newColors = defaultColors[defaultColors.length - 1];
|
||||
for (var i = defaultColors.length; i < numberOfValues; i++) {
|
||||
newColors.push(defaultColors[defaultColors.length - 1][defaultColors.length - 1]);
|
||||
}
|
||||
return newColors;
|
||||
}
|
||||
else {
|
||||
throw "Incorrect input and no default colors can be provided";
|
||||
}
|
||||
};
|
||||
return Colors;
|
||||
}());
|
||||
exports.Colors = Colors;
|
||||
});
|
|
@ -1,38 +0,0 @@
|
|||
define(["require", "exports", 'chai', './colors'], function (require, exports, chai_1, colors_1) {
|
||||
"use strict";
|
||||
describe("Colors", function () {
|
||||
var defaultColors = [
|
||||
["red"],
|
||||
["red", "blue"],
|
||||
["red", "yellow", "blue"],
|
||||
["red", "orange", "yellow", "blue"],
|
||||
["red", "orange", "yellow", "blue", "dark blue"],
|
||||
["dark red", "red", "orange", "yellow", "blue", "dark blue"],
|
||||
["dark red", "red", "orange", "yellow", "blue", "dark blue", "purple"]
|
||||
];
|
||||
it("outputs color array for 1 value", function () {
|
||||
chai_1.expect(colors_1.Colors.getColors(1)).to.be.deep.equal((defaultColors[0]));
|
||||
});
|
||||
it("outputs color array for 3 values", function () {
|
||||
chai_1.expect(colors_1.Colors.getColors(3)).to.be.deep.equal((defaultColors[2]));
|
||||
});
|
||||
it("outputs color array for 7 values", function () {
|
||||
chai_1.expect(colors_1.Colors.getColors(7)).to.be.deep.equal((defaultColors[6]));
|
||||
});
|
||||
it("outputs color array for 8 values", function () {
|
||||
chai_1.expect(colors_1.Colors.getColors(8)).to.be.deep.equal((["dark red", "red", "orange", "yellow", "blue", "dark blue", "purple", "purple"]));
|
||||
});
|
||||
it("outputs color array for 15 values", function () {
|
||||
chai_1.expect(colors_1.Colors.getColors(15)).to.be.deep.equal((["dark red", "red", "orange", "yellow", "blue", "dark blue", "purple", "purple", "purple", "purple", "purple", "purple", "purple", "purple", "purple"]));
|
||||
});
|
||||
it("throws exception for invalid input of negative", function () {
|
||||
chai_1.expect(function () { return colors_1.Colors.getColors(-1); }).throws(("Incorrect input and no default colors can be provided"));
|
||||
});
|
||||
it("throws exception for invalid input of 0", function () {
|
||||
chai_1.expect(function () { return colors_1.Colors.getColors(0); }).throws(("Incorrect input and no default colors can be provided"));
|
||||
});
|
||||
it("throws exception for invalid input of null/undefined", function () {
|
||||
chai_1.expect(function () { return colors_1.Colors.getColors(null); }).throws(("Incorrect input and no default colors can be provided"));
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,36 +0,0 @@
|
|||
define(["require", "exports", "TFS/WorkItemTracking/Services", "./InputParser", "./model", "./view", "./errorView"], function (require, exports, WitService, InputParser_1, model_1, view_1, errorView_1) {
|
||||
"use strict";
|
||||
var Controller = (function () {
|
||||
function Controller() {
|
||||
this._fieldName = "";
|
||||
this._initialize();
|
||||
}
|
||||
Controller.prototype._initialize = function () {
|
||||
var _this = this;
|
||||
this._inputs = VSS.getConfiguration().witInputs;
|
||||
this._fieldName = InputParser_1.InputParser.getFieldName(this._inputs);
|
||||
WitService.WorkItemFormService.getService().then(function (service) {
|
||||
Q.spread([service.getAllowedFieldValues(_this._fieldName), service.getFieldValue(_this._fieldName)], function (allowedValues, currentValue) {
|
||||
var options = InputParser_1.InputParser.getOptions(_this._inputs, allowedValues);
|
||||
_this._model = new model_1.Model(options, currentValue);
|
||||
_this._view = new view_1.colorControl(_this._model, function (val) {
|
||||
_this.update(val);
|
||||
});
|
||||
}, _this.handleError);
|
||||
}, this.handleError);
|
||||
};
|
||||
Controller.prototype.handleError = function (error) {
|
||||
var errorView = new errorView_1.ErrorView(error);
|
||||
};
|
||||
Controller.prototype.update = function (value) {
|
||||
var _this = this;
|
||||
WitService.WorkItemFormService.getService().then(function (service) {
|
||||
service.setFieldValue(_this._fieldName, value).then(function () {
|
||||
_this._model.setSelectedValue(value);
|
||||
_this._view.update(value);
|
||||
}, _this.handleError);
|
||||
}, this.handleError);
|
||||
};
|
||||
return Controller;
|
||||
}());
|
||||
});
|
|
@ -1,3 +0,0 @@
|
|||
define(["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
});
|
|
@ -1,23 +0,0 @@
|
|||
define(["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
var ErrorView = (function () {
|
||||
function ErrorView(error) {
|
||||
var container = $("<div />");
|
||||
container.addClass("container");
|
||||
var warning = $("<p />");
|
||||
warning.prepend('<span class="bowtie-icon">bowtie-status-warning</span>');
|
||||
warning.text(error);
|
||||
container.append(warning);
|
||||
var help = $("<p />");
|
||||
help.text("See ");
|
||||
var a = $("<a> </a>");
|
||||
a.attr("href", "https://www.visualstudio.com/en-us/products/visual-studio-team-services-vs.aspx");
|
||||
a.text("Documentation.");
|
||||
help.append(a);
|
||||
container.append(help);
|
||||
$('body').empty().append(container);
|
||||
}
|
||||
return ErrorView;
|
||||
}());
|
||||
exports.ErrorView = ErrorView;
|
||||
});
|
|
@ -1,46 +0,0 @@
|
|||
define(["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
var Model = (function () {
|
||||
function Model(options, initialValue) {
|
||||
this._options = [];
|
||||
this._options = options;
|
||||
this._selectedValue = initialValue;
|
||||
}
|
||||
Model.prototype.setSelectedValue = function (value) {
|
||||
for (var _i = 0, _a = this._options; _i < _a.length; _i++) {
|
||||
var option = _a[_i];
|
||||
if (option.value === value) {
|
||||
this._selectedValue = value;
|
||||
this._selectedOption = option;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this._selectedValue !== value) {
|
||||
throw "Selected value not within original values";
|
||||
}
|
||||
};
|
||||
Model.prototype.selectPreviousOption = function () {
|
||||
var index = this._options.indexOf(this._selectedOption);
|
||||
if (index > 0) {
|
||||
this.setSelectedValue(this._options[index - 1].value);
|
||||
}
|
||||
};
|
||||
Model.prototype.selectNextOption = function () {
|
||||
var index = this._options.indexOf(this._selectedOption);
|
||||
if (index < (this._options.length - 1)) {
|
||||
this.setSelectedValue(this._options[index + 1].value);
|
||||
}
|
||||
};
|
||||
Model.prototype.getSelectedValue = function () {
|
||||
return this._selectedValue;
|
||||
};
|
||||
Model.prototype.getSelectedOption = function () {
|
||||
return this._selectedOption;
|
||||
};
|
||||
Model.prototype.getOptions = function () {
|
||||
return this._options;
|
||||
};
|
||||
return Model;
|
||||
}());
|
||||
exports.Model = Model;
|
||||
});
|
|
@ -1,71 +0,0 @@
|
|||
define(["require", "exports", 'chai', './model'], function (require, exports, chai_1, model_1) {
|
||||
"use strict";
|
||||
describe("Model", function () {
|
||||
var model;
|
||||
var options = [
|
||||
{
|
||||
value: "1",
|
||||
color: "Red",
|
||||
label: "High"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
color: "Blue",
|
||||
label: "Medium"
|
||||
},
|
||||
{
|
||||
value: "3",
|
||||
color: "Green",
|
||||
label: "Low"
|
||||
}
|
||||
];
|
||||
var testOption = {
|
||||
value: "4",
|
||||
color: "Purple",
|
||||
label: "Very Low"
|
||||
};
|
||||
beforeEach(function () {
|
||||
model = new model_1.Model(options, options[0].value);
|
||||
});
|
||||
it("outputs selected value for 1st option", function () {
|
||||
chai_1.expect(model.getSelectedValue()).to.be.deep.equal(options[0].value);
|
||||
});
|
||||
it("outputs selected value for 2nd option", function () {
|
||||
model.setSelectedValue(options[1].value);
|
||||
chai_1.expect(model.getSelectedValue()).to.be.deep.equal(options[1].value);
|
||||
});
|
||||
it("outputs selected option for 2nd option", function () {
|
||||
model.setSelectedValue(options[1].value);
|
||||
chai_1.expect(model.getSelectedOption()).to.be.deep.equal(options[1]);
|
||||
});
|
||||
it("throws exception for selected value that is not one of values", function () {
|
||||
chai_1.expect(function () { return model.setSelectedValue(testOption.value); }).throws("Selected value not within original values");
|
||||
});
|
||||
it("throws exception for selected value that is null", function () {
|
||||
chai_1.expect(function () { return model.setSelectedValue(null); }).throws("Selected value not within original values");
|
||||
});
|
||||
it("throws exception for selected value that is null", function () {
|
||||
chai_1.expect(function () { return model.setSelectedValue(undefined); }).throws("Selected value not within original values");
|
||||
});
|
||||
it("outputs previous option for 1st selected option: gives first option", function () {
|
||||
model.setSelectedValue(options[0].value);
|
||||
model.selectPreviousOption();
|
||||
chai_1.expect(model.getSelectedOption()).to.be.deep.equal(options[0]);
|
||||
});
|
||||
it("outputs previous option for last selected option: gives last option", function () {
|
||||
model.setSelectedValue(options[2].value);
|
||||
model.selectNextOption();
|
||||
chai_1.expect(model.getSelectedOption()).to.be.deep.equal(options[2]);
|
||||
});
|
||||
it("outputs previous option for 2nd selected option", function () {
|
||||
model.setSelectedValue(options[1].value);
|
||||
model.selectPreviousOption();
|
||||
chai_1.expect(model.getSelectedOption()).to.be.deep.equal(options[0]);
|
||||
});
|
||||
it("outputs next option for 2nd selected option", function () {
|
||||
model.setSelectedValue(options[1].value);
|
||||
model.selectNextOption();
|
||||
chai_1.expect(model.getSelectedOption()).to.be.deep.equal(options[2]);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,113 +0,0 @@
|
|||
define(["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
var colorRow = (function () {
|
||||
function colorRow(allowedValue, color, label) {
|
||||
this.allowedValue = allowedValue;
|
||||
this.color = color;
|
||||
this.label = label;
|
||||
}
|
||||
colorRow.prototype.create = function () {
|
||||
this._row = $("<div> </div>");
|
||||
this._row.data("value", this.allowedValue);
|
||||
this._row.addClass("row");
|
||||
var valueColor = $("<div> </div>");
|
||||
valueColor.addClass("valueColor");
|
||||
var color = this.color;
|
||||
valueColor.css("background-color", this.color);
|
||||
this._row.append(valueColor);
|
||||
var valueLabel = $("<div> </div>");
|
||||
valueLabel.addClass("valueLabel");
|
||||
if (!this.label) {
|
||||
valueLabel.text(this.allowedValue);
|
||||
}
|
||||
else {
|
||||
valueLabel.text(this.allowedValue + " - " + this.label);
|
||||
}
|
||||
;
|
||||
this._row.append(valueLabel);
|
||||
return this._row;
|
||||
};
|
||||
colorRow.prototype.select = function () {
|
||||
this._row.addClass("selected");
|
||||
};
|
||||
colorRow.prototype.unselect = function () {
|
||||
this._row.removeClass("selected");
|
||||
};
|
||||
return colorRow;
|
||||
}());
|
||||
exports.colorRow = colorRow;
|
||||
var colorControl = (function () {
|
||||
function colorControl(model, onItemClicked) {
|
||||
this.model = model;
|
||||
this.onItemClicked = onItemClicked;
|
||||
this.rows = [];
|
||||
this.init();
|
||||
}
|
||||
colorControl.prototype.init = function () {
|
||||
var _this = this;
|
||||
var container = $("<div> </div>");
|
||||
container.addClass("container");
|
||||
var rowSelected = this.model.getSelectedOption();
|
||||
var options = this.model.getOptions();
|
||||
for (var _i = 0, options_1 = options; _i < options_1.length; _i++) {
|
||||
var option = options_1[_i];
|
||||
var row = new colorRow(option.value, option.color, option.label);
|
||||
this.rows.push(row);
|
||||
container.append(row.create());
|
||||
var selected = option.value === rowSelected.value;
|
||||
if (selected) {
|
||||
row.select();
|
||||
}
|
||||
else {
|
||||
row.unselect();
|
||||
}
|
||||
}
|
||||
var callback = function (evt) {
|
||||
if (evt.keyCode == 40) {
|
||||
if (rowSelected) {
|
||||
_this.model.selectNextOption();
|
||||
var itemClicked = _this.model.getSelectedOption();
|
||||
if (_this.onItemClicked) {
|
||||
_this.onItemClicked(itemClicked.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (evt.keyCode == 38) {
|
||||
if (rowSelected) {
|
||||
_this.model.selectPreviousOption();
|
||||
var next = _this.model.getSelectedOption();
|
||||
var itemClicked = next.value;
|
||||
if (_this.onItemClicked) {
|
||||
_this.onItemClicked(itemClicked.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
container.click(function (evt) {
|
||||
var itemClicked = $(evt.target).closest(".row").data("value");
|
||||
if (_this.onItemClicked) {
|
||||
_this.onItemClicked(itemClicked);
|
||||
}
|
||||
});
|
||||
container.keydown(function (evt) {
|
||||
callback(evt);
|
||||
}).keyup(function (evt) {
|
||||
callback(evt);
|
||||
});
|
||||
$('body').empty().append(container);
|
||||
};
|
||||
colorControl.prototype.update = function (value) {
|
||||
for (var _i = 0, _a = this.rows; _i < _a.length; _i++) {
|
||||
var row = _a[_i];
|
||||
if (row.allowedValue == value) {
|
||||
row.select();
|
||||
}
|
||||
else {
|
||||
row.unselect();
|
||||
}
|
||||
}
|
||||
};
|
||||
return colorControl;
|
||||
}());
|
||||
exports.colorControl = colorControl;
|
||||
});
|
Загрузка…
Ссылка в новой задаче