Added Google JavaScript Style Guide and fixed errors
diff --git a/xos/core/xoslib/.eslintignore b/xos/core/xoslib/.eslintignore
new file mode 100644
index 0000000..be5c014
--- /dev/null
+++ b/xos/core/xoslib/.eslintignore
@@ -0,0 +1,4 @@
+node_modules/**/*.js
+static/js/xsh/**/*.js
+static/js/vendor/**/*.js
+spec/helpers/*.js
\ No newline at end of file
diff --git a/xos/core/xoslib/.eslintrc b/xos/core/xoslib/.eslintrc
index 211611c..3615cae 100644
--- a/xos/core/xoslib/.eslintrc
+++ b/xos/core/xoslib/.eslintrc
@@ -1,9 +1,9 @@
{
+ "extends": "defaults/configurations/google",
"env" : {
"browser": true
},
"rules" : {
- "quotes": [1, "double"],
"camelcase": [0],
"no-underscore-dangle": [0],
"eqeqeq": [1],
@@ -13,9 +13,15 @@
"beforeColon": false,
"afterColon": true
}],
- "indent": [2, 4],
- "valid-jsdoc": 2
+ "valid-jsdoc": 2,
+ "max-len": [1, 120, 4, {"ignoreComments": true, "ignoreUrls": true}],
+ brace-style: [2, "stroustrup"]
},
"globals": {
+ "$": false,
+ "_": false,
+ "Backbone": false,
+ "Marionette": false,
+ "xos": false
}
}
diff --git a/xos/core/xoslib/package.json b/xos/core/xoslib/package.json
index 831f182..cc23dbf 100644
--- a/xos/core/xoslib/package.json
+++ b/xos/core/xoslib/package.json
@@ -11,13 +11,14 @@
"author": "",
"license": "BSD-2-Clause",
"devDependencies": {
- "karma": "~0.13.10",
+ "eslint": "~1.6.0",
+ "eslint-config-defaults": "^7.0.1",
"jasmine-core": "~2.3.4",
- "karma-jasmine": "~0.3.6",
- "phantomjs": "~1.9.18",
- "karma-phantomjs-launcher": "~0.2.1",
- "karma-mocha-reporter": "~1.1.1",
+ "karma": "~0.13.10",
"karma-babel-preprocessor": "~5.2.2",
- "eslint": "~1.6.0"
+ "karma-jasmine": "~0.3.6",
+ "karma-mocha-reporter": "~1.1.1",
+ "karma-phantomjs-launcher": "~0.2.1",
+ "phantomjs": "~1.9.18"
}
}
diff --git a/xos/core/xoslib/spec/.eslintrc b/xos/core/xoslib/spec/.eslintrc
index 1fbd34e..eb98f18 100644
--- a/xos/core/xoslib/spec/.eslintrc
+++ b/xos/core/xoslib/spec/.eslintrc
@@ -29,7 +29,9 @@
"beforeColon": false,
"afterColon": true
}],
- "indent": [2, 2]
+ "indent": [2, 2],
+ "no-undef": [0],
+ "newline-after-var": [0]
},
"globals": {
"console": false,
@@ -41,6 +43,8 @@
"beforeEach": false,
"after": false,
"afterEach": false,
- "expect": false
+ "expect": false,
+ "jasmine": false,
+ "spyOn": false
}
}
diff --git a/xos/core/xoslib/spec/views/helloworld.test.js b/xos/core/xoslib/spec/views/helloworld.test.js
new file mode 100644
index 0000000..1d8ea86
--- /dev/null
+++ b/xos/core/xoslib/spec/views/helloworld.test.js
@@ -0,0 +1,12 @@
+'use strict';
+
+describe('The HelloWorld template', () => {
+
+ beforeEach(() => {
+ spyOn(xos.slices, 'startPolling');
+ });
+
+ xit('should call startPolling method', () => {
+ expect(xos.slices.startPolling).toHaveBeenCalled();
+ });
+});
diff --git a/xos/core/xoslib/spec/xoslib/xos-backbone.test.js b/xos/core/xoslib/spec/xoslib/xos-backbone.test.js
index fa749d3..f14275d 100644
--- a/xos/core/xoslib/spec/xoslib/xos-backbone.test.js
+++ b/xos/core/xoslib/spec/xoslib/xos-backbone.test.js
@@ -1,7 +1,7 @@
'use strict';
describe('The Xos Backbone', () => {
-
+
beforeEach(() => {
xosdefaults = {
test: {config: true}
@@ -23,7 +23,7 @@
});
describe('The extend_defaults method', () => {
-
+
it('should return an extended config', () => {
let extended = extend_defaults('test', {extended: true});
expect(extended).toEqual({config: true, extended: true});
@@ -37,6 +37,11 @@
});
describe('getCookie method with no cookie', () => {
+
+ beforeEach(() => {
+ document.cookie = 'fakeCookie=true=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
+ });
+
it('should return null', () => {
let res = getCookie('fakeCookie');
expect(res).toBeNull();
@@ -44,11 +49,11 @@
});
describe('getCookie method with a fake cookie', () => {
-
+
beforeEach(() => {
document.cookie = 'fakeCookie=true';
});
-
+
it('should return a cookie value', () => {
let res = getCookie('fakeCookie');
expect(res).toEqual('true');
@@ -68,18 +73,18 @@
it('should set the correct url', () => {
const ctx = {attributes: {resource_uri: 'onlab.us'}};
let res = model.url.apply(ctx);
- expect(res).toEqual('onlab.us/?no_hyperlinks=1')
+ expect(res).toEqual('onlab.us/?no_hyperlinks=1');
});
it('should remove query params', () => {
const ctx = {attributes: {resource_uri: 'onlab.us?query=params'}};
let res = model.url.apply(ctx);
- expect(res).toEqual('onlab.us/?no_hyperlinks=1')
+ expect(res).toEqual('onlab.us/?no_hyperlinks=1');
});
});
describe('listMethods method', () => {
-
+
const instance = {
m1: () => {},
m2: () => {}
@@ -132,7 +137,7 @@
const instance = {
validators: {'network_ports': ['portspec']}
- }
+ };
const validAttrs = {network_ports: 'tcp 123'};
diff --git a/xos/core/xoslib/spec/xoslib/xos-utils.test.js b/xos/core/xoslib/spec/xoslib/xos-utils.test.js
index ec06768..fd0193e 100644
--- a/xos/core/xoslib/spec/xoslib/xos-utils.test.js
+++ b/xos/core/xoslib/spec/xoslib/xos-utils.test.js
@@ -60,12 +60,12 @@
describe('The fieldNameToHumanReadable method', () => {
it('should convert lodash to spaces and apply toTitleCase', () => {
let res = fieldNameToHumanReadable('tEst_fIelD');
- expect(res).toEqual('Test Field')
+ expect(res).toEqual('Test Field');
});
});
describe('The limitTableRows', () => {
-
+
beforeEach(() => {
f.load('table_rows.html');
});
@@ -169,8 +169,8 @@
it('should set elements to same width', () => {
make_same_width('.container', 'div');
- $('.container div').each(function(){
- expect($(this)).toHaveCss({width: '400px'});
+ $('.container div').each(function(index, item) {
+ expect($(item)).toHaveCss({width: '400px'});
});
});
});
@@ -218,14 +218,14 @@
it('should throw an error for malformed separator', () => {
let res = () => {
return parse_portlist('tcp+123, tcp+124');
- }
+ };
expect(res).toThrow('malformed port specifier tcp+123, format example: "tcp 123, tcp 201:206, udp 333"');
});
it('should should throw if unknown protocol', () => {
let res = () => {
parse_portlist('abc 123');
- }
+ };
expect(res).toThrow('unknown protocol abc');
});
});
diff --git a/xos/core/xoslib/static/js/gentle.js b/xos/core/xoslib/static/js/gentle.js
index f79bde2..008886a 100644
--- a/xos/core/xoslib/static/js/gentle.js
+++ b/xos/core/xoslib/static/js/gentle.js
@@ -1,49 +1,50 @@
+
var ContactManager = new Marionette.Application();
ContactManager.addRegions({
- mainRegion: "#main-region"
+ mainRegion: '#main-region'
});
ContactManager.Contact = Backbone.Model.extend({});
ContactManager.ContactCollection = Backbone.Collection.extend({
- model: ContactManager.Contact
+ model: ContactManager.Contact
});
ContactManager.ContactItemView = Marionette.ItemView.extend({
- tagName: "li",
- template: "#contact-list-item"
+ tagName: 'li',
+ template: '#contact-list-item'
});
ContactManager.ContactsView = Marionette.CollectionView.extend({
- tagName: "ul",
- childView: ContactManager.ContactItemView
+ tagName: 'ul',
+ childView: ContactManager.ContactItemView
});
-ContactManager.on("start", function(){
- var contacts = new ContactManager.ContactCollection([
- {
- firstName: "Bob",
- lastName: "Brigham",
- phoneNumber: "555-0163"
- },
- {
- firstName: "Alice",
- lastName: "Arten",
- phoneNumber: "555-0184"
- },
- {
- firstName: "Charlie",
- lastName: "Campbell",
- phoneNumber: "555-0129"
- }
- ]);
+ContactManager.on('start', function() {
+ var contacts = new ContactManager.ContactCollection([
+ {
+ firstName: 'Bob',
+ lastName: 'Brigham',
+ phoneNumber: '555-0163'
+ },
+ {
+ firstName: 'Alice',
+ lastName: 'Arten',
+ phoneNumber: '555-0184'
+ },
+ {
+ firstName: 'Charlie',
+ lastName: 'Campbell',
+ phoneNumber: '555-0129'
+ }
+ ]);
- var contactsView = new ContactManager.ContactsView({
- collection: contacts
- });
+ var contactsView = new ContactManager.ContactsView({
+ collection: contacts
+ });
- ContactManager.mainRegion.show(contactsView);
+ ContactManager.mainRegion.show(contactsView);
});
ContactManager.start();
diff --git a/xos/core/xoslib/static/js/helloworld.js b/xos/core/xoslib/static/js/helloworld.js
index 1563094..d34a968 100644
--- a/xos/core/xoslib/static/js/helloworld.js
+++ b/xos/core/xoslib/static/js/helloworld.js
@@ -1,27 +1,38 @@
+/* eslint-disable guard-for-in */
+
// helloworld.js
function updateHelloWorldData() {
- var html = "<table class='table table-bordered table-striped'>";
- for (var slicekey in xos.slices.models) {
- slice = xos.slices.models[slicekey]
- html = html + "<tr><td>" + slice.get("name") + "</td><td>" + slice.get("description") + "</td></tr>";
- }
- html = html + "</table>";
- $('#dynamicTableOfInterestingThings').html(html);
+ var html = '<table class="table table-bordered table-striped">';
+
+ for (var slicekey in xos.slices.models) {
+ var slice = xos.slices.models[slicekey];
+
+ html = html + '<tr><td>' + slice.get('name') + '</td><td>' + slice.get('description') + '</td></tr>';
+ }
+ html = html + '</table>';
+ $('#dynamicTableOfInterestingThings').html(html);
}
-$(document).ready(function(){
- xos.slices.on("change", function() { updateHelloWorldData(); });
- xos.slices.on("remove", function() { updateHelloWorldData(); });
- xos.slices.on("sort", function() { updateHelloWorldData(); });
+$(document).ready(function() {
+ xos.slices.on('change', function() {
+ updateHelloWorldData();
+ });
+ xos.slices.on('remove', function() {
+ updateHelloWorldData();
+ });
+ xos.slices.on('sort', function() {
+ updateHelloWorldData();
+ });
- xos.slices.startPolling();
+ xos.slices.startPolling();
});
// helloworld.js
$(document).ready(function() {
- $('#submitNewDescription').bind('click', function() {
- newDescription = $("#newDescription").val();
- xos.slices.models[0].set("description", newDescription);
- xos.slices.models[0].save();
- });
+ $('#submitNewDescription').bind('click', function() {
+ var newDescription = $('#newDescription').val();
+
+ xos.slices.models[0].set('description', newDescription);
+ xos.slices.models[0].save();
+ });
});
diff --git a/xos/core/xoslib/static/js/picker.js b/xos/core/xoslib/static/js/picker.js
index 075bdc5..35b6cd1 100644
--- a/xos/core/xoslib/static/js/picker.js
+++ b/xos/core/xoslib/static/js/picker.js
@@ -1,54 +1,55 @@
-function init_picker(selector, ordered) {
- //console.log("init_picker");
- //console.log($(selector));
-
- var addBtn = $(selector).find(".btn-picker-add");
- var removeBtn = $(selector).find(".btn-picker-remove");
- var upBtn = $(selector).find(".btn-picker-up");
- var downBtn = $(selector).find(".btn-picker-down");
- var from = $(selector).find(".select-picker-from");
- var to = $(selector).find(".select-picker-to");
-
- if (!ordered) {
- upBtn.hide();
- downBtn.hide();
- }
-
- addBtn.click(function(){
- console.log("add");
- from.find(":selected").each( function() {
- to.append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>");
- $(this).remove();
- });
+function init_picker(selector, ordered) {
+ //console.log("init_picker");
+ //console.log($(selector));
+
+ var addBtn = $(selector).find('.btn-picker-add');
+ var removeBtn = $(selector).find('.btn-picker-remove');
+ var upBtn = $(selector).find('.btn-picker-up');
+ var downBtn = $(selector).find('.btn-picker-down');
+ var from = $(selector).find('.select-picker-from');
+ var to = $(selector).find('.select-picker-to');
+
+ if (!ordered) {
+ upBtn.hide();
+ downBtn.hide();
+ }
+
+ addBtn.click(function() {
+ from.find(':selected').each(function() {
+ to.append('<option value="' + $(this).val() + '"">' + $(this).text() + '</option>');
+ $(this).remove();
});
- removeBtn.click(function(){
- console.log("remove");
- to.find(":selected").each( function() {
- from.append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>");
- $(this).remove();
- });
+ });
+ removeBtn.click(function() {
+ to.find(':selected').each(function() {
+ from.append('<option value="' + $(this).val() + '">' + $(this).text() + '</option>');
+ $(this).remove();
});
- upBtn.bind('click', function() {
- to.find(":selected").each( function() {
- var newPos = to.find('option').index(this) - 1;
- if (newPos > -1) {
- to.find("option").eq(newPos).before("<option value='"+$(this).val()+"' selected='selected'>"+$(this).text()+"</option>");
- $(this).remove();
- }
- });
+ });
+ upBtn.bind('click', function() {
+ to.find(':selected').each(function() {
+ var newPos = to.find('option').index(this) - 1;
+
+ if (newPos > -1) {
+ to.find('option').eq(newPos).before('<option value="' + $(this).val() + '" selected="selected">' + $(this).text() + '</option>');
+ $(this).remove();
+ }
});
- downBtn.bind('click', function() {
- var countOptions = to.find("option").size();
- to.find(":selected").each( function() {
- var newPos = to.find("option").index(this) + 1;
- if (newPos < countOptions) {
- to.find("option").eq(newPos).after("<option value='"+$(this).val()+"' selected='selected'>"+$(this).text()+"</option>");
- $(this).remove();
- }
- });
+ });
+ downBtn.bind('click', function() {
+ var countOptions = to.find('option').size();
+
+ to.find(':selected').each(function() {
+ var newPos = to.find('option').index(this) + 1;
+
+ if (newPos < countOptions) {
+ to.find('option').eq(newPos).after('<option value="' + $(this).val() + '" selected="selected">' + $(this).text() + '</option>');
+ $(this).remove();
+ }
});
+ });
};
function init_spinner(selector, value) {
- var spinner = $(selector).spinner( "value", value);
+ $(selector).spinner('value', value);
};
diff --git a/xos/core/xoslib/static/js/sliceEditor.js b/xos/core/xoslib/static/js/sliceEditor.js
index c629944..12ed86f 100644
--- a/xos/core/xoslib/static/js/sliceEditor.js
+++ b/xos/core/xoslib/static/js/sliceEditor.js
@@ -1,23 +1,24 @@
-/* This is a demo of using xoslib with Marionette
-
- The main window is split into two halves. The left half has a CollectionView
- (SliceListView) that lists all slices the user has access to. The right half
- has an ItemView (SliceDetailView) that allows the user to edit the
- name and description of a slice, as well as a <Save> button to save it.
-*/
-
-SliceEditorApp = new Marionette.Application();
-
-SliceEditorApp.addRegions({
- sliceList: "#sliceEditorList",
- sliceDetail: "#sliceEditorDetail",
-});
-
-/* SliceListItemView: This is the item view that is used by SliceListView to
- display slice names.
-*/
-
-SliceEditorApp.SliceListItemView = Marionette.ItemView.extend({
+/* eslint-disable */
+/* This is a demo of using xoslib with Marionette
+
+ The main window is split into two halves. The left half has a CollectionView
+ (SliceListView) that lists all slices the user has access to. The right half
+ has an ItemView (SliceDetailView) that allows the user to edit the
+ name and description of a slice, as well as a <Save> button to save it.
+*/
+
+SliceEditorApp = new Marionette.Application();
+
+SliceEditorApp.addRegions({
+ sliceList: "#sliceEditorList",
+ sliceDetail: "#sliceEditorDetail",
+});
+
+/* SliceListItemView: This is the item view that is used by SliceListView to
+ display slice names.
+*/
+
+SliceEditorApp.SliceListItemView = Marionette.ItemView.extend({
template: "#sliceeditor-listitem-template",
tagName: 'li',
className: 'sliceeditor-listitem',
@@ -47,8 +48,8 @@
/* SliceListView: This displays a list of slice names.
*/
-
-SliceEditorApp.SliceListView = Marionette.CollectionView.extend({
+
+SliceEditorApp.SliceListView = Marionette.CollectionView.extend({
tagName: "ul",
childView: SliceEditorApp.SliceListItemView,
@@ -95,16 +96,16 @@
this.dirty = false;
},
});
-
-SliceEditorApp.on("start", function() {
- var sliceListView = new SliceEditorApp.SliceListView({
+
+SliceEditorApp.on("start", function() {
+ var sliceListView = new SliceEditorApp.SliceListView({
collection: xos.slicesPlus
});
SliceEditorApp.sliceList.show(sliceListView);
xos.slicesPlus.startPolling();
-});
-
-$(document).ready(function(){
- SliceEditorApp.start();
-});
-
+});
+
+$(document).ready(function(){
+ SliceEditorApp.start();
+});
+/* eslint-enable */
diff --git a/xos/core/xoslib/static/js/sliverListTest.js b/xos/core/xoslib/static/js/sliverListTest.js
index 3a0c1fb..4b60697 100644
--- a/xos/core/xoslib/static/js/sliverListTest.js
+++ b/xos/core/xoslib/static/js/sliverListTest.js
@@ -1,3 +1,4 @@
+/* eslint-disable */
(function(){
window.InstanceView = Backbone.View.extend({
@@ -144,3 +145,4 @@
});
});
})();
+/* eslint-enable */
diff --git a/xos/core/xoslib/static/js/test.js b/xos/core/xoslib/static/js/test.js
index bb32760..9135134 100644
--- a/xos/core/xoslib/static/js/test.js
+++ b/xos/core/xoslib/static/js/test.js
@@ -1,3 +1,4 @@
+/* eslint-disable */
TestApp = new XOSApplication();
TestApp.addRegions({
@@ -19,22 +20,22 @@
});
//TestApp.navigateToDetail = function(detailView) {
-// $(TestApp.detailBoxId).show();
-// TestApp.detail.show(detailView);
-//};
-
-TestApp.navigateToModel = function(app, detailClass, detailNavLink, model) {
-
- var detailView = new detailClass({
- model: model,
- });
-
- $(app.detailBoxId).show();
- app.detail.show(detailView);
- detailView.showLinkedItems();
-};
-
-TestApp.on("start", function() {
+// $(TestApp.detailBoxId).show();
+// TestApp.detail.show(detailView);
+//};
+
+TestApp.navigateToModel = function(app, detailClass, detailNavLink, model) {
+
+ var detailView = new detailClass({
+ model: model,
+ });
+
+ $(app.detailBoxId).show();
+ app.detail.show(detailView);
+ detailView.showLinkedItems();
+};
+
+TestApp.on("start", function() {
var objs = ['deployment', 'image', 'networkTemplate', 'network', 'port', 'networkDeployment', 'node', 'service', 'site', 'slice', 'sliceDeployment', 'slicePrivilege', 'instance', 'user', 'sliceRole', 'userDeployment'];
for (var index in objs) {
@@ -46,9 +47,9 @@
region_name = name + "List";
detailClass = XOSDetailView.extend({
- template: detail_template,
- app: TestApp,
- });
+ template: detail_template,
+ app: TestApp,
+ });
itemViewClass = XOSItemView.extend({
detailClass: detailClass,
@@ -81,4 +82,4 @@
$(document).ready(function(){
TestApp.start();
});
-
+/* eslint-enable */
diff --git a/xos/core/xoslib/static/js/xosAdminSite.js b/xos/core/xoslib/static/js/xosAdminSite.js
index 13f1d67..78e6f8d 100644
--- a/xos/core/xoslib/static/js/xosAdminSite.js
+++ b/xos/core/xoslib/static/js/xosAdminSite.js
@@ -1,34 +1,35 @@
-OBJS = ['deployment', 'image', 'networkTemplate', 'network', 'port',
- 'node', 'service', 'site', 'slice', 'slicePrivilege', 'instance',
- 'user', 'sliceRole', 'flavor', 'controller', 'siteDeployment',
- 'controller_image', 'controller_network', 'controller_slice', 'controller_user'];
-NAV_OBJS = ['deployment', 'site', 'slice', 'user'];
-
-REWRITES = {"/admin/core/deployment/": "#deployments",
- "/admin/core/site/" : "#sites",
- "/admin/core/slice/" : "#slices",
- "/admin/core/user/" : "#users"};
-
-XOSAdminApp = new XOSApplication({
- logTableId: "#logTable",
- statusMsgId: "#statusMsg",
- hideTabsByDefault: true
-});
-
-XOSAdminApp.addRegions({
- navigation: "#navigationPanel",
-
- detail: "#detail",
- linkedObjs1: "#linkedObjs1",
- linkedObjs2: "#linkedObjs2",
- linkedObjs3: "#linkedObjs3",
- linkedObjs4: "#linkedObjs4",
-
- addChildDetail: "#xos-addchild-detail",
-
- rightButtonPanel: "#rightButtonPanel"
-});
-
+/* eslint-disable */
+OBJS = ['deployment', 'image', 'networkTemplate', 'network', 'port',
+ 'node', 'service', 'site', 'slice', 'slicePrivilege', 'instance',
+ 'user', 'sliceRole', 'flavor', 'controller', 'siteDeployment',
+ 'controller_image', 'controller_network', 'controller_slice', 'controller_user'];
+NAV_OBJS = ['deployment', 'site', 'slice', 'user'];
+
+REWRITES = {"/admin/core/deployment/": "#deployments",
+ "/admin/core/site/" : "#sites",
+ "/admin/core/slice/" : "#slices",
+ "/admin/core/user/" : "#users"};
+
+XOSAdminApp = new XOSApplication({
+ logTableId: "#logTable",
+ statusMsgId: "#statusMsg",
+ hideTabsByDefault: true
+});
+
+XOSAdminApp.addRegions({
+ navigation: "#navigationPanel",
+
+ detail: "#detail",
+ linkedObjs1: "#linkedObjs1",
+ linkedObjs2: "#linkedObjs2",
+ linkedObjs3: "#linkedObjs3",
+ linkedObjs4: "#linkedObjs4",
+
+ addChildDetail: "#xos-addchild-detail",
+
+ rightButtonPanel: "#rightButtonPanel"
+});
+
XOSAdminApp.navigate = function(what, modelName, modelId) {
console.log("XOSAsminApp.navigate");
collection_name = modelName + "s";
@@ -82,35 +83,35 @@
XOSAdminApp["genericListView"] = genericListViewClass;
for (var index in OBJS) {
- name = OBJS[index];
- tr_template = '#xosAdmin-' + name + '-listitem-template';
- table_template = '#xosAdmin-' + name + '-list-template';
- detail_template = '#xosAdmin-' + name + '-detail-template';
- add_child_template = '#xosAdmin-' + name + '-add-child-template';
- collection_name = name + "s";
- region_name = name + "List";
-
- if (window["XOSDetailView_" + name]) {
- detailClass = window["XOSDetailView_" + name].extend({template: "#xos-detail-template",
- app: XOSAdminApp});
- } else {
- detailClass = genericDetailClass;
- }
- if ($(detail_template).length) {
- detailClass = detailClass.extend({
+ name = OBJS[index];
+ tr_template = '#xosAdmin-' + name + '-listitem-template';
+ table_template = '#xosAdmin-' + name + '-list-template';
+ detail_template = '#xosAdmin-' + name + '-detail-template';
+ add_child_template = '#xosAdmin-' + name + '-add-child-template';
+ collection_name = name + "s";
+ region_name = name + "List";
+
+ if (window["XOSDetailView_" + name]) {
+ detailClass = window["XOSDetailView_" + name].extend({template: "#xos-detail-template",
+ app: XOSAdminApp});
+ } else {
+ detailClass = genericDetailClass;
+ }
+ if ($(detail_template).length) {
+ detailClass = detailClass.extend({
template: detail_template,
});
}
XOSAdminApp[collection_name + "DetailView"] = detailClass;
if (window["XOSDetailView_" + name]) {
- addClass = window["XOSDetailView_" + name].extend({template: "#xos-add-template",
- app: XOSAdminApp});
- } else {
- addClass = genericAddChildClass;
- }
- if ($(add_child_template).length) {
- addClass = detailClass.extend({
+ addClass = window["XOSDetailView_" + name].extend({template: "#xos-add-template",
+ app: XOSAdminApp});
+ } else {
+ addClass = genericAddChildClass;
+ }
+ if ($(add_child_template).length) {
+ addClass = detailClass.extend({
template: add_child_template,
});
}
@@ -119,30 +120,30 @@
if ($(tr_template).length) {
itemViewClass = XOSItemView.extend({
template: tr_template,
- app: XOSAdminApp,
- });
- } else {
- itemViewClass = genericItemViewClass;
- }
-
- if ($(table_template).length) {
- listViewClass = XOSListView.extend({
- childView: itemViewClass,
- template: table_template,
- collection: xos[collection_name],
- title: name + "s",
- app: XOSAdminApp,
- });
- } else {
- listViewClass = genericListViewClass.extend( { childView: itemViewClass,
- collection: xos[collection_name],
- title: name + "s",
- } );
- }
-
- XOSAdminApp[collection_name + "ListView"] = listViewClass;
-
- xos[collection_name].fetch(); //startPolling();
+ app: XOSAdminApp,
+ });
+ } else {
+ itemViewClass = genericItemViewClass;
+ }
+
+ if ($(table_template).length) {
+ listViewClass = XOSListView.extend({
+ childView: itemViewClass,
+ template: table_template,
+ collection: xos[collection_name],
+ title: name + "s",
+ app: XOSAdminApp,
+ });
+ } else {
+ listViewClass = genericListViewClass.extend( { childView: itemViewClass,
+ collection: xos[collection_name],
+ title: name + "s",
+ } );
+ }
+
+ XOSAdminApp[collection_name + "ListView"] = listViewClass;
+
+ xos[collection_name].fetch(); //startPolling();
}
};
@@ -226,22 +227,22 @@
};
XOSAdminApp.on("start", function() {
- XOSAdminApp.buildViews();
-
- XOSAdminApp.initRouter();
-
- XOSAdminApp.updateNavigationPanel();
-
- XOSAdminApp.rewriteLinks();
-
- // fire it once to initially show the progress bar
- XOSAdminApp.collectionLoadChange();
-
- // fire it each time the collection load status is updated
- Backbone.on("xoslib:collectionLoadChange", XOSAdminApp.collectionLoadChange);
-});
-
-$(document).ready(function(){
- XOSAdminApp.start();
-});
-
+ XOSAdminApp.buildViews();
+
+ XOSAdminApp.initRouter();
+
+ XOSAdminApp.updateNavigationPanel();
+
+ XOSAdminApp.rewriteLinks();
+
+ // fire it once to initially show the progress bar
+ XOSAdminApp.collectionLoadChange();
+
+ // fire it each time the collection load status is updated
+ Backbone.on("xoslib:collectionLoadChange", XOSAdminApp.collectionLoadChange);
+});
+
+$(document).ready(function(){
+ XOSAdminApp.start();
+});
+/* eslint-enable */
diff --git a/xos/core/xoslib/static/js/xosCord.js b/xos/core/xoslib/static/js/xosCord.js
index f666b77..c9be375 100644
--- a/xos/core/xoslib/static/js/xosCord.js
+++ b/xos/core/xoslib/static/js/xosCord.js
@@ -1,25 +1,26 @@
-OBJS = ['cordSubscriber', 'cordUser']
-
-CordAdminApp = new XOSApplication({
- logTableId: "#logTable",
- statusMsgId: "#statusMsg",
- hideTabsByDefault: true
-});
-
-CordAdminApp.addRegions({
- navigation: "#navigationPanel",
-
- detail: "#detail",
- linkedObjs1: "#linkedObjs1",
- linkedObjs2: "#linkedObjs2",
- linkedObjs3: "#linkedObjs3",
- linkedObjs4: "#linkedObjs4",
-
- addChildDetail: "#xos-addchild-detail",
-
- rightButtonPanel: "#rightButtonPanel"
-});
-
+/* eslint-disable */
+OBJS = ['cordSubscriber', 'cordUser'];
+
+CordAdminApp = new XOSApplication({
+ logTableId: "#logTable",
+ statusMsgId: "#statusMsg",
+ hideTabsByDefault: true
+});
+
+CordAdminApp.addRegions({
+ navigation: "#navigationPanel",
+
+ detail: "#detail",
+ linkedObjs1: "#linkedObjs1",
+ linkedObjs2: "#linkedObjs2",
+ linkedObjs3: "#linkedObjs3",
+ linkedObjs4: "#linkedObjs4",
+
+ addChildDetail: "#xos-addchild-detail",
+
+ rightButtonPanel: "#rightButtonPanel"
+});
+
CordAdminApp.navigate = function(what, modelName, modelId) {
collection_name = modelName + "s";
if (what=="list") {
@@ -51,36 +52,36 @@
CordAdminApp["genericListView"] = genericListViewClass;
for (var index in OBJS) {
- name = OBJS[index];
- tr_template = '#xosAdmin-' + name + '-listitem-template';
- table_template = '#xosAdmin-' + name + '-list-template';
- detail_template = '#xosAdmin-' + name + '-detail-template';
- add_child_template = '#xosAdmin-' + name + '-add-child-template';
- collection_name = name + "s";
- region_name = name + "List";
- templates = {cordSubscriber: "#xos-cord-subscriber-template"};
-
- if (window["XOSDetailView_" + name]) {
- detailClass = window["XOSDetailView_" + name].extend( {template: templates[name] || "#xos-detail-template",
- app: CordAdminApp});
- } else {
- detailClass = genericDetailClass.extend( {template: templates[name] || "#xos-detail-template", });
- }
- if ($(detail_template).length) {
- detailClass = detailClass.extend({
+ name = OBJS[index];
+ tr_template = '#xosAdmin-' + name + '-listitem-template';
+ table_template = '#xosAdmin-' + name + '-list-template';
+ detail_template = '#xosAdmin-' + name + '-detail-template';
+ add_child_template = '#xosAdmin-' + name + '-add-child-template';
+ collection_name = name + "s";
+ region_name = name + "List";
+ templates = {cordSubscriber: "#xos-cord-subscriber-template"};
+
+ if (window["XOSDetailView_" + name]) {
+ detailClass = window["XOSDetailView_" + name].extend( {template: templates[name] || "#xos-detail-template",
+ app: CordAdminApp});
+ } else {
+ detailClass = genericDetailClass.extend( {template: templates[name] || "#xos-detail-template", });
+ }
+ if ($(detail_template).length) {
+ detailClass = detailClass.extend({
template: detail_template,
});
}
CordAdminApp[collection_name + "DetailView"] = detailClass;
if (window["XOSDetailView_" + name]) {
- addClass = window["XOSDetailView_" + name].extend({template: "#xos-add-template",
- app: CordAdminApp});
- } else {
- addClass = genericAddChildClass;
- }
- if ($(add_child_template).length) {
- addClass = detailClass.extend({
+ addClass = window["XOSDetailView_" + name].extend({template: "#xos-add-template",
+ app: CordAdminApp});
+ } else {
+ addClass = genericAddChildClass;
+ }
+ if ($(add_child_template).length) {
+ addClass = detailClass.extend({
template: add_child_template,
});
}
@@ -89,30 +90,30 @@
if ($(tr_template).length) {
itemViewClass = XOSItemView.extend({
template: tr_template,
- app: CordAdminApp,
- });
- } else {
- itemViewClass = genericItemViewClass;
- }
-
- if ($(table_template).length) {
- listViewClass = XOSListView.extend({
- childView: itemViewClass,
- template: table_template,
- collection: xos[collection_name],
- title: name + "s",
- app: CordAdminApp,
- });
- } else {
- listViewClass = genericListViewClass.extend( { childView: itemViewClass,
- collection: xos[collection_name],
- title: name + "s",
- } );
- }
-
- CordAdminApp[collection_name + "ListView"] = listViewClass;
-
- xos[collection_name].fetch(); //startPolling();
+ app: CordAdminApp,
+ });
+ } else {
+ itemViewClass = genericItemViewClass;
+ }
+
+ if ($(table_template).length) {
+ listViewClass = XOSListView.extend({
+ childView: itemViewClass,
+ template: table_template,
+ collection: xos[collection_name],
+ title: name + "s",
+ app: CordAdminApp,
+ });
+ } else {
+ listViewClass = genericListViewClass.extend( { childView: itemViewClass,
+ collection: xos[collection_name],
+ title: name + "s",
+ } );
+ }
+
+ CordAdminApp[collection_name + "ListView"] = listViewClass;
+
+ xos[collection_name].fetch(); //startPolling();
}
};
@@ -179,18 +180,18 @@
};
CordAdminApp.on("start", function() {
- CordAdminApp.buildViews();
-
- CordAdminApp.initRouter();
-
- // fire it once to initially show the progress bar
- CordAdminApp.collectionLoadChange();
-
- // fire it each time the collection load status is updated
- Backbone.on("xoslib:collectionLoadChange", CordAdminApp.collectionLoadChange);
-});
-
-$(document).ready(function(){
- CordAdminApp.start();
-});
-
+ CordAdminApp.buildViews();
+
+ CordAdminApp.initRouter();
+
+ // fire it once to initially show the progress bar
+ CordAdminApp.collectionLoadChange();
+
+ // fire it each time the collection load status is updated
+ Backbone.on("xoslib:collectionLoadChange", CordAdminApp.collectionLoadChange);
+});
+
+$(document).ready(function(){
+ CordAdminApp.start();
+});
+/* eslint-enable */
diff --git a/xos/core/xoslib/static/js/xosDeveloper.js b/xos/core/xoslib/static/js/xosDeveloper.js
index aef640e..e4e5afb 100644
--- a/xos/core/xoslib/static/js/xosDeveloper.js
+++ b/xos/core/xoslib/static/js/xosDeveloper.js
@@ -1,62 +1,64 @@
-/* This is an example that uses xoslib + marionette to display the developer
-
view.
+/* eslint-disable guard-for-in, no-undef*/
+/* This is an example that uses xoslib + marionette to display the developer
+ view.
-
For an example that uses xoslib + datatables, see xosDeveloper_datatables.js
-
*/
+ For an example that uses xoslib + datatables, see xosDeveloper_datatables.js
+*/
-
DeveloperApp = new Marionette.Application();
+DeveloperApp = new Marionette.Application();
DeveloperApp.addRegions({
- mainRegion: "#developerView"
-});
-
-DeveloperApp.SliceDetailView = Marionette.ItemView.extend({
- template: "#developer-slicedetail-template",
+ mainRegion: '#developerView'
+});
+
+DeveloperApp.SliceDetailView = Marionette.ItemView.extend({
+ template: '#developer-slicedetail-template',
tagName: 'tr',
className: 'developer_slicedetail'
-});
-
-DeveloperApp.SliceListView = Marionette.CompositeView.extend({
- tagName: "table",
- className: "table table-bordered table-striped",
- template: "#developer-slicetable-template",
- childView: DeveloperApp.SliceDetailView,
- childViewContainer: "tbody",
+});
- events: {"click .sort": "changeSort"},
+DeveloperApp.SliceListView = Marionette.CompositeView.extend({
+ tagName: 'table',
+ className: 'table table-bordered table-striped',
+ template: '#developer-slicetable-template',
+ childView: DeveloperApp.SliceDetailView,
+ childViewContainer: 'tbody',
+
+ events: {'click .sort': 'changeSort'},
initialize: function() {
- this.listenTo(this.collection, 'change', this._renderChildren);
+ this.listenTo(this.collection, 'change', this._renderChildren);
},
changeSort: function(e) {
- parts=$(e.currentTarget).attr("id").split('-');
- order=parts[1];
- fieldName=parts[2];
- this.collection.sortVar = fieldName;
- this.collection.sortOrder = order;
- this.collection.sort();
+ parts = $(e.currentTarget).attr('id').split('-');
+ order = parts[1];
+ fieldName = parts[2];
+ this.collection.sortVar = fieldName;
+ this.collection.sortOrder = order;
+ this.collection.sort();
},
attachHtml: function(compositeView, childView, index) {
- // The REST API will let admin users see everything. For the developer
- // view we still want to hide slices we are not members of.
- if (childView.model.get("sliceInfo").roles.length == 0) {
- return;
- }
- DeveloperApp.SliceListView.__super__.attachHtml(compositeView, childView, index);
+ // The REST API will let admin users see everything. For the developer
+ // view we still want to hide slices we are not members of.
+ if(childView.model.get('sliceInfo').roles.length == 0) {
+ return;
+ }
+ DeveloperApp.SliceListView.__super__.attachHtml(compositeView, childView, index);
},
});
-
-DeveloperApp.on("start", function() {
- var developerSliceListView = new DeveloperApp.SliceListView({
+
+DeveloperApp.on('start', function() {
+ var developerSliceListView = new DeveloperApp.SliceListView({
collection: xos.slicesPlus
});
+
DeveloperApp.mainRegion.show(developerSliceListView);
xos.slicesPlus.startPolling();
-});
-
-$(document).ready(function(){
- DeveloperApp.start();
-});
-
+});
+
+$(document).ready(function() {
+ DeveloperApp.start();
+});
+
diff --git a/xos/core/xoslib/static/js/xosDeveloper_datatables.js b/xos/core/xoslib/static/js/xosDeveloper_datatables.js
index ed88a9f..fc0153b 100644
--- a/xos/core/xoslib/static/js/xosDeveloper_datatables.js
+++ b/xos/core/xoslib/static/js/xosDeveloper_datatables.js
@@ -1,50 +1,62 @@
+/* eslint-disable guard-for-in, no-undef, indent*/
+
+// TODO write test and then fix lint errors
+
/* This is an example that uses xoslib + datatables to display the developer
-
view.
-
-
For an example that uses xoslib + marionette, see xosDeveloper.js
-
*/
-
-
function updateSliceTable(data) {
-
$('#developerView').html( '<table cellpadding="0" cellspacing="0" border="0" class="display" id="dynamicusersliceinfo"></table>' );
+ view.
+
+ For an example that uses xoslib + marionette, see xosDeveloper.js
+*/
+
+function updateSliceTable(data) {
+ $('#developerView').html('<table cellpadding="0" cellspacing="0" border="0" class="display" id="dynamicusersliceinfo"></table>');
var actualEntries = [];
for (rowkey in data.models) {
row = data.models[rowkey];
- slicename = row.get("name");
- sliceid = row.get("id");
- role = row.get("sliceInfo").roles[0] || "";
- instancecount = row.get("sliceInfo").instanceCount;
- sitecount = row.get("sliceInfo").siteCount;
- backendHtml = row.get("backendHtml")
+ slicename = row.get('name');
+ sliceid = row.get('id');
+ role = row.get('sliceInfo').roles[0] || '';
+ instancecount = row.get('sliceInfo').instanceCount;
+ sitecount = row.get('sliceInfo').siteCount;
+ backendHtml = row.get('backendHtml');
//if (! role) {
// continue;
//}
- if (! row.get("current_user_can_see") ) {
+ if (! row.get('current_user_can_see')) {
continue;
}
- actualEntries.push([backendHtml + ' <a href="/admin/core/slice/' + sliceid + '">' + slicename + '</a>',
- role, instancecount, sitecount]);
+ actualEntries.push([backendHtml +
+ ' <a href="/admin/core/slice/' + sliceid + '">' +
+ slicename + '</a>',
+ role, instancecount, sitecount]);
}
- oTable = $('#dynamicusersliceinfo').dataTable( {
- "bJQueryUI": true,
- "aaData": actualEntries ,
- "bStateSave": true,
- "aoColumns": [
- { "sTitle": "Slice" },
- { "sTitle": "Privilege" , sClass: "alignCenter"},
- { "sTitle": "Number of Instances" , sClass: "alignCenter"},
- { "sTitle": "Number of Sites" , sClass: "alignCenter"},
+ oTable = $('#dynamicusersliceinfo').dataTable({
+ 'bJQueryUI': true,
+ 'aaData': actualEntries,
+ 'bStateSave': true,
+ 'aoColumns': [
+ {'sTitle': 'Slice'},
+ {'sTitle': 'Privilege' , sClass: 'alignCenter'},
+ {'sTitle': 'Number of Instances' , sClass: 'alignCenter'},
+ {'sTitle': 'Number of Sites' , sClass: 'alignCenter'},
]
- } );
+ });
}
-$(document).ready(function(){
- xos.slicesPlus.on("change", function() { /*console.log("change");*/ updateSliceTable(xos.slicesPlus); });
- xos.slicesPlus.on("remove", function() { /*console.log("sort");*/ updateSliceTable(xos.slicesPlus); });
- xos.slicesPlus.on("sort", function() { /*console.log("sort");*/ updateSliceTable(xos.slicesPlus); });
+$(document).ready(function() {
+ xos.slicesPlus.on('change', function() {
+ updateSliceTable(xos.slicesPlus);
+ });
+ xos.slicesPlus.on('remove', function() {
+ updateSliceTable(xos.slicesPlus);
+ });
+ xos.slicesPlus.on('sort', function() {
+ updateSliceTable(xos.slicesPlus);
+ });
xos.slicesPlus.startPolling();
});
diff --git a/xos/core/xoslib/static/js/xosHpc.js b/xos/core/xoslib/static/js/xosHpc.js
index a87fdd1..e0b0437 100644
--- a/xos/core/xoslib/static/js/xosHpc.js
+++ b/xos/core/xoslib/static/js/xosHpc.js
@@ -1,3 +1,4 @@
+/* eslint-disable */
SC_RR = 60;
SC_HPC_PROBE = 600;
SC_HPC_FETCH = 3600;
@@ -101,5 +102,4 @@
xos.hpcview.startPolling();
});
-
-
+/* eslint-enable */
diff --git a/xos/core/xoslib/static/js/xosHpcNodes.js b/xos/core/xoslib/static/js/xosHpcNodes.js
index 729e167..850aeca 100644
--- a/xos/core/xoslib/static/js/xosHpcNodes.js
+++ b/xos/core/xoslib/static/js/xosHpcNodes.js
@@ -1,3 +1,4 @@
+/* eslint-disable */
SC_HPC_FETCH = 3600;
var hpc_data = null;
@@ -104,5 +105,5 @@
xos.hpcview.startPolling();
});
-
+/* eslint-enable */
diff --git a/xos/core/xoslib/static/js/xosHpcUrls.js b/xos/core/xoslib/static/js/xosHpcUrls.js
index 3a8cfe0..cda7b2d 100644
--- a/xos/core/xoslib/static/js/xosHpcUrls.js
+++ b/xos/core/xoslib/static/js/xosHpcUrls.js
@@ -1,3 +1,4 @@
+/* eslint-disable */
SC_HPC_FETCH = 3600;
var hpc_data = null;
@@ -88,4 +89,4 @@
xos.hpcview.startPolling();
});
-
+/* eslint-enable */
diff --git a/xos/core/xoslib/static/js/xosTenant.js b/xos/core/xoslib/static/js/xosTenant.js
index 414cb48..d2a3b4e 100644
--- a/xos/core/xoslib/static/js/xosTenant.js
+++ b/xos/core/xoslib/static/js/xosTenant.js
@@ -1,152 +1,154 @@
-XOSTenantSite = XOSModel.extend( {
- listFields: ["name", "allocated"],
- modelName: "tenantSite",
- collectionName: "tenantSites"
-});
-
-XOSTenantSiteCollection = XOSCollection.extend( {
- listFields: ["name", "allocated", "ready"],
- modelName: "tenantSite",
- collectionName: "tenantSites",
-
- getFromSlice: function(slice) {
- var tenantSites = [];
- var id = 0;
- for (siteName in slice.attributes.site_allocation) {
- allocated = slice.attributes.site_allocation[siteName];
- ready = slice.attributes.site_ready[siteName] || 0;
- tenantSites.push(new XOSTenantSite( { name: siteName, allocated: allocated, ready: ready, id: id} ));
- id = id + 1;
- }
- for (index in xos.tenantview.models[0].attributes.blessed_site_names) {
- siteName = xos.tenantview.models[0].attributes.blessed_site_names[index];
- if (! (siteName in slice.attributes.site_allocation)) {
- tenantSites.push(new XOSTenantSite( { name: siteName, allocated: 0, ready: 0, id: id} ));
- id = id + 1;
- }
- }
- this.set(tenantSites);
-
- var that=this;
- this.listenTo(slice, 'change', function() { that.getReadyFromSlice(slice); })
- },
-
- getReadyFromSlice: function(slice) {
- for (siteName in slice.attributes.site_ready) {
- ready = slice.attributes.site_ready[siteName];
- for (index in this.models) {
- tenantSite = this.models[index];
- if (tenantSite.attributes.name == siteName) {
- tenantSite.set("ready", ready);
- }
- }
- }
- },
-
- putToSlice: function(slice) {
- slice.attributes.site_allocation = {};
- for (index in this.models) {
- var model = this.models[index];
- slice.attributes.site_allocation[ model.attributes.name ] = model.attributes.allocated;
- }
- },
-});
-
-XOSEditUsersView = Marionette.ItemView.extend({
- template: "#tenant-edit-users",
- viewInitializers: [],
-
- onShow: function() {
- _.each(this.viewInitializers, function(initializer) {
- initializer();
- });
- },
-
- templateHelpers: function() { return { detailView: this, model: this.model }; },
-
- });
-
-XOSTenantSummaryView = XOSDetailView.extend({
- events: {"change": "onChange"},
-
- onChange: function(e) {
- XOSTenantApp.setDirty(true);
- },
-
- saveSuccess: function() {
- console.log("saveSuccess!");
- XOSTenantApp.setDirty(false);
- },
-
- });
-
-
-XOSTenantButtonView = Marionette.ItemView.extend({
- template: "#xos-tenant-buttons-template",
-
- events: {"click button.btn-tenant-create": "createClicked",
- "click button.btn-tenant-delete": "deleteClicked",
- "click button.btn-tenant-add-user": "addUserClicked",
- "click button.btn-tenant-save": "saveClicked",
- "click button.btn-tenant-download-ssh": "downloadClicked",
- },
-
- createClicked: function(e) {
- XOSTenantApp.addSlice();
- },
-
- deleteClicked: function(e) {
- XOSTenantApp.deleteSlice(this.options.linkedView.model);
- },
-
- addUserClicked: function(e) {
- XOSTenantApp.editUsers(this.options.linkedView.model);
- },
-
- downloadClicked: function(e) {
- XOSTenantApp.downloadSSH(this.options.linkedView.model);
- },
-
- saveClicked: function(e) {
- model = this.options.linkedView.model;
- model.tenantSiteCollection.putToSlice(model);
- model.attributes.users = model.usersBuffer;
-
- e.preventDefault();
- this.options.linkedView.save();
- //this.options.linkedView.submitContinueClicked.call(this.options.linkedView, e);
- //XOSTenantApp.setDirty(false);
- },
- });
-
-XOSTenantApp = new XOSApplication({
- logTableId: "#logTable",
- statusMsgId: "#statusMsg",
- hideTabsByDefault: true,
- dirty: false,
- varName: "XOSTenantApp",
-});
-
-XOSTenantApp.addRegions({
- tenantSliceSelector: "#tenantSliceSelector",
- tenantSummary: "#tenantSummary",
- tenantSiteList: "#tenantSiteList",
- tenantButtons: "#tenantButtons",
- tenantAddSliceInterior: "#tenant-addslice-interior",
- tenantEditUsersInterior: "#tenant-edit-users-interior",
- tenantSSHCommandsInterior: "#tenant-ssh-commands-interior",
-});
-
-XOSTenantApp.setDirty = function(dirty) {
- XOSTenantApp.dirty = dirty;
- if (dirty) {
- $("button.btn-tenant-save").addClass("btn-success");
- } else {
- $("button.btn-tenant-save").removeClass("btn-success");
- }
-};
-
-XOSTenantApp.buildViews = function() {
+/* eslint-disable */
+
+XOSTenantSite = XOSModel.extend( {
+ listFields: ["name", "allocated"],
+ modelName: "tenantSite",
+ collectionName: "tenantSites"
+});
+
+XOSTenantSiteCollection = XOSCollection.extend( {
+ listFields: ["name", "allocated", "ready"],
+ modelName: "tenantSite",
+ collectionName: "tenantSites",
+
+ getFromSlice: function(slice) {
+ var tenantSites = [];
+ var id = 0;
+ for (siteName in slice.attributes.site_allocation) {
+ allocated = slice.attributes.site_allocation[siteName];
+ ready = slice.attributes.site_ready[siteName] || 0;
+ tenantSites.push(new XOSTenantSite( { name: siteName, allocated: allocated, ready: ready, id: id} ));
+ id = id + 1;
+ }
+ for (index in xos.tenantview.models[0].attributes.blessed_site_names) {
+ siteName = xos.tenantview.models[0].attributes.blessed_site_names[index];
+ if (! (siteName in slice.attributes.site_allocation)) {
+ tenantSites.push(new XOSTenantSite( { name: siteName, allocated: 0, ready: 0, id: id} ));
+ id = id + 1;
+ }
+ }
+ this.set(tenantSites);
+
+ var that=this;
+ this.listenTo(slice, 'change', function() { that.getReadyFromSlice(slice); })
+ },
+
+ getReadyFromSlice: function(slice) {
+ for (siteName in slice.attributes.site_ready) {
+ ready = slice.attributes.site_ready[siteName];
+ for (index in this.models) {
+ tenantSite = this.models[index];
+ if (tenantSite.attributes.name == siteName) {
+ tenantSite.set("ready", ready);
+ }
+ }
+ }
+ },
+
+ putToSlice: function(slice) {
+ slice.attributes.site_allocation = {};
+ for (index in this.models) {
+ var model = this.models[index];
+ slice.attributes.site_allocation[ model.attributes.name ] = model.attributes.allocated;
+ }
+ },
+});
+
+XOSEditUsersView = Marionette.ItemView.extend({
+ template: "#tenant-edit-users",
+ viewInitializers: [],
+
+ onShow: function() {
+ _.each(this.viewInitializers, function(initializer) {
+ initializer();
+ });
+ },
+
+ templateHelpers: function() { return { detailView: this, model: this.model }; },
+
+ });
+
+XOSTenantSummaryView = XOSDetailView.extend({
+ events: {"change": "onChange"},
+
+ onChange: function(e) {
+ XOSTenantApp.setDirty(true);
+ },
+
+ saveSuccess: function() {
+ console.log("saveSuccess!");
+ XOSTenantApp.setDirty(false);
+ },
+
+ });
+
+
+XOSTenantButtonView = Marionette.ItemView.extend({
+ template: "#xos-tenant-buttons-template",
+
+ events: {"click button.btn-tenant-create": "createClicked",
+ "click button.btn-tenant-delete": "deleteClicked",
+ "click button.btn-tenant-add-user": "addUserClicked",
+ "click button.btn-tenant-save": "saveClicked",
+ "click button.btn-tenant-download-ssh": "downloadClicked",
+ },
+
+ createClicked: function(e) {
+ XOSTenantApp.addSlice();
+ },
+
+ deleteClicked: function(e) {
+ XOSTenantApp.deleteSlice(this.options.linkedView.model);
+ },
+
+ addUserClicked: function(e) {
+ XOSTenantApp.editUsers(this.options.linkedView.model);
+ },
+
+ downloadClicked: function(e) {
+ XOSTenantApp.downloadSSH(this.options.linkedView.model);
+ },
+
+ saveClicked: function(e) {
+ model = this.options.linkedView.model;
+ model.tenantSiteCollection.putToSlice(model);
+ model.attributes.users = model.usersBuffer;
+
+ e.preventDefault();
+ this.options.linkedView.save();
+ //this.options.linkedView.submitContinueClicked.call(this.options.linkedView, e);
+ //XOSTenantApp.setDirty(false);
+ },
+ });
+
+XOSTenantApp = new XOSApplication({
+ logTableId: "#logTable",
+ statusMsgId: "#statusMsg",
+ hideTabsByDefault: true,
+ dirty: false,
+ varName: "XOSTenantApp",
+});
+
+XOSTenantApp.addRegions({
+ tenantSliceSelector: "#tenantSliceSelector",
+ tenantSummary: "#tenantSummary",
+ tenantSiteList: "#tenantSiteList",
+ tenantButtons: "#tenantButtons",
+ tenantAddSliceInterior: "#tenant-addslice-interior",
+ tenantEditUsersInterior: "#tenant-edit-users-interior",
+ tenantSSHCommandsInterior: "#tenant-ssh-commands-interior",
+});
+
+XOSTenantApp.setDirty = function(dirty) {
+ XOSTenantApp.dirty = dirty;
+ if (dirty) {
+ $("button.btn-tenant-save").addClass("btn-success");
+ } else {
+ $("button.btn-tenant-save").removeClass("btn-success");
+ }
+};
+
+XOSTenantApp.buildViews = function() {
XOSTenantApp.tenantSites = new XOSTenantSiteCollection();
tenantSummaryClass = XOSTenantSummaryView.extend({template: "#xos-detail-template",
@@ -250,22 +252,22 @@
detailView.dialog = $("#tenant-addslice-dialog");
app.tenantAddSliceInterior.show(detailView);
$("#tenant-addslice-dialog").dialog({
- autoOpen: false,
- modal: true,
- width: 640,
- buttons : {
- "Create Slice" : function() {
- var addDialog = this;
- console.log("SAVE!!!");
- detailView.synchronous = true;
- detailView.afterSave = function() { $(addDialog).dialog("close"); XOSTenantApp.navToSlice(detailView.model.id); }
- detailView.save();
- },
- "Cancel" : function() {
- $(this).dialog("close");
- }
- }
- });
+ autoOpen: false,
+ modal: true,
+ width: 640,
+ buttons : {
+ "Create Slice" : function() {
+ var addDialog = this;
+ console.log("SAVE!!!");
+ detailView.synchronous = true;
+ detailView.afterSave = function() { $(addDialog).dialog("close"); XOSTenantApp.navToSlice(detailView.model.id); }
+ detailView.save();
+ },
+ "Cancel" : function() {
+ $(this).dialog("close");
+ }
+ }
+ });
$("#tenant-addslice-dialog").dialog("open");
};
@@ -275,25 +277,25 @@
detailView.dialog = $("#tenant-edit-users-dialog");
app.tenantEditUsersInterior.show(detailView);
$("#tenant-edit-users-dialog").dialog({
- autoOpen: false,
- modal: true,
- width: 640,
- buttons : {
- "Ok" : function() {
- var editDialog = this;
- user_ids = all_options($("#tenant-edit-users-dialog").find(".select-picker-to"));
- user_ids = user_ids.map( function(x) { return parseInt(x,10); } );
- if (!array_same_elements(user_ids, model.usersBuffer)) {
- XOSTenantApp.setDirty(true);
- }
- model.usersBuffer = user_ids;
- $(editDialog).dialog("close");
- },
- "Cancel" : function() {
- $(this).dialog("close");
- }
- }
- });
+ autoOpen: false,
+ modal: true,
+ width: 640,
+ buttons : {
+ "Ok" : function() {
+ var editDialog = this;
+ user_ids = all_options($("#tenant-edit-users-dialog").find(".select-picker-to"));
+ user_ids = user_ids.map( function(x) { return parseInt(x,10); } );
+ if (!array_same_elements(user_ids, model.usersBuffer)) {
+ XOSTenantApp.setDirty(true);
+ }
+ model.usersBuffer = user_ids;
+ $(editDialog).dialog("close");
+ },
+ "Cancel" : function() {
+ $(this).dialog("close");
+ }
+ }
+ });
$("#tenant-edit-users-dialog").dialog("open");
};
@@ -313,23 +315,23 @@
XOSTenantApp.tenantSSHCommandsInterior.show(htmlView);
$("#tenant-ssh-commands-dialog").dialog({
- autoOpen: false,
- modal: true,
- width: 640,
- buttons : {
- "Download": function() {
- var dlLink = document.createElement('a');
- dlLink.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(sshCommands));
- dlLink.setAttribute('download', 'sshcommands.txt');
- dlLink.click();
-
- //window.open('data:text/text,' + encodeURIComponent(sshCommands));
- },
- "Close" : function() {
- $(this).dialog("close");
- },
- }
- });
+ autoOpen: false,
+ modal: true,
+ width: 640,
+ buttons : {
+ "Download": function() {
+ var dlLink = document.createElement('a');
+ dlLink.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(sshCommands));
+ dlLink.setAttribute('download', 'sshcommands.txt');
+ dlLink.click();
+
+ //window.open('data:text/text,' + encodeURIComponent(sshCommands));
+ },
+ "Close" : function() {
+ $(this).dialog("close");
+ },
+ }
+ });
$("#tenant-ssh-commands-dialog").dialog("open");
};
@@ -439,16 +441,16 @@
};
XOSTenantApp.on("start", function() {
- XOSTenantApp.buildViews();
-
- // fire it once to initially show the progress bar
- XOSTenantApp.collectionLoadChange();
-
- // fire it each time the collection load status is updated
- Backbone.on("xoslib:collectionLoadChange", XOSTenantApp.collectionLoadChange);
-});
-
-$(document).ready(function(){
- XOSTenantApp.start();
-});
-
+ XOSTenantApp.buildViews();
+
+ // fire it once to initially show the progress bar
+ XOSTenantApp.collectionLoadChange();
+
+ // fire it each time the collection load status is updated
+ Backbone.on("xoslib:collectionLoadChange", XOSTenantApp.collectionLoadChange);
+});
+
+$(document).ready(function(){
+ XOSTenantApp.start();
+});
+/* eslint-enable */
diff --git a/xos/core/xoslib/static/js/xoslib/xos-backbone.js b/xos/core/xoslib/static/js/xoslib/xos-backbone.js
index 3e43279..6fb6cc1 100644
--- a/xos/core/xoslib/static/js/xoslib/xos-backbone.js
+++ b/xos/core/xoslib/static/js/xoslib/xos-backbone.js
@@ -1,4 +1,6 @@
-if (! window.XOSLIB_LOADED ) {
+/* eslint-disable*/
+
+if (! window.XOSLIB_LOADED) {
window.XOSLIB_LOADED=true;
XOS_BASE = "/xos";
@@ -59,7 +61,8 @@
if (!url) {
if (this.id) {
url = this.urlRoot + this.id;
- } else {
+ }
+ else {
// this happens when creating a new model.
url = this.urlRoot;
}
@@ -67,12 +70,12 @@
if (!url) {
// XXX I'm not sure this does anything useful
- url = ( _.isFunction( this.collection.url ) ? this.collection.url() : this.collection.url );
+ url = _.isFunction(this.collection.url) ? this.collection.url() : this.collection.url;
url = url || this.urlRoot;
}
// remove any existing query parameters
- url && ( url.indexOf("?") > -1 ) && ( url = url.split("?")[0] );
+ url && url.indexOf("?") > -1 && (url = url.split("?")[0]);
url && ( url += ( url.length > 0 && url.charAt( url.length - 1 ) === '/' ) ? '' : '/' );
@@ -135,7 +138,7 @@
_.each(validatorList, function(validator) {
if (fieldName in attrs) {
// call validateField method in xos-utils.js
- validatorResult = validateField(validator, attrs[fieldName], this)
+ validatorResult = validateField(validator, attrs[fieldName], this);
if (validatorResult != true) {
errors[fieldName] = validatorResult;
foundErrors = true;
@@ -160,16 +163,18 @@
XOSCollection = Backbone.Collection.extend({
objects: function() {
- return this.models.map(function(element) { return element.attributes; });
+ return this.models.map(function(element) {
+ return element.attributes;
+ });
},
- initialize: function(){
+ initialize: function() {
this.isLoaded = false;
this.failedLoad = false;
this.startedLoad = false;
this.sortVar = 'name';
this.sortOrder = 'asc';
- this.on( "sort", this.sorted );
+ this.on('sort', this.sorted);
},
relatedCollections: [],
@@ -183,7 +188,7 @@
//console.log("sorted " + this.modelName);
},
- simpleComparator: function( model ){
+ simpleComparator: function(model) {
parts=this.sortVar.split(".");
result = model.get(parts[0]);
for (index=1; index<parts.length; ++index) {
@@ -192,16 +197,21 @@
return result;
},
- comparator: function (left, right) {
+ comparator: function(left, right) {
var l = this.simpleComparator(left);
var r = this.simpleComparator(right);
- if (l === void 0) return -1;
- if (r === void 0) return 1;
+ if (l === void 0) {
+ return -1;
+ }
+ if (r === void 0) {
+ return 1;
+ }
if (this.sortOrder == "desc") {
return l < r ? 1 : l > r ? -1 : 0;
- } else {
+ }
+ else {
return l < r ? -1 : l > r ? 1 : 0;
}
},
@@ -223,7 +233,7 @@
fetchFailure: function(collection, response, options) {
//console.log("fetch failed " + collection.modelName);
this.fetching = false;
- if ((!this.isLoaded) && (!this.failedLoad)) {
+ if (!this.isLoaded && !this.failedLoad) {
this.failedLoad=true;
Backbone.trigger("xoslib:collectionLoadChange", this);
}
@@ -235,6 +245,7 @@
fetch: function(options) {
var self=this;
+
this.fetching=true;
//console.log("fetch " + this.modelName);
if (!this.startedLoad) {
@@ -247,7 +258,9 @@
}
options["orig_success"] = options["success"];
options["orig_failure"] = options["failure"];
- options["success"] = function(collection, response, options) { self.fetchSuccess.call(self, collection, response, options); };
+ options["success"] = function(collection, response, options) {
+ self.fetchSuccess.call(self, collection, response, options);
+ };
options["failure"] = this.fetchFailure;
Backbone.Collection.prototype.fetch.call(this, options);
},
@@ -255,7 +268,10 @@
startPolling: function() {
if (!this._polling) {
var collection=this;
- setInterval(function() { collection.fetch(); }, 10000);
+
+ setInterval(function() {
+ collection.fetch();
+ }, 10000);
this._polling=true;
this.fetch();
}
@@ -823,3 +839,4 @@
};
})();
}
+/* eslint-enable */
\ No newline at end of file
diff --git a/xos/core/xoslib/static/js/xoslib/xos-defaults.js b/xos/core/xoslib/static/js/xoslib/xos-defaults.js
index 12d2755..0f4ab27 100644
--- a/xos/core/xoslib/static/js/xoslib/xos-defaults.js
+++ b/xos/core/xoslib/static/js/xoslib/xos-defaults.js
@@ -1,3 +1,4 @@
+/* eslint-disable quotes, no-undef, max-len, new-cap*/
/* eslint indent: [2, 2]*/
function xos_get_defaults() {
this.account = {"updated": null, "policed": null, "created": null, "deleted": false, "site": null, "lazy_blocked": false, "backend_register": "{}", "write_protect": false, "backend_status": "0 - Provisioning in progress", "no_sync": false, "enacted": null};
@@ -65,3 +66,4 @@
this.userDashboardView = {"updated": null, "policed": null, "created": null, "deleted": false, "dashboardView": null, "lazy_blocked": false, "backend_register": "{}", "write_protect": false, "user": null, "backend_status": "0 - Provisioning in progress", "order": 0, "no_sync": false, "enacted": null};
};
xosdefaults = new xos_get_defaults();
+/* eslint-enable quotes, no-undef, max-len, new-cap*/
\ No newline at end of file
diff --git a/xos/core/xoslib/static/js/xoslib/xos-util.js b/xos/core/xoslib/static/js/xoslib/xos-util.js
index 7512290..66c01ce 100644
--- a/xos/core/xoslib/static/js/xoslib/xos-util.js
+++ b/xos/core/xoslib/static/js/xoslib/xos-util.js
@@ -1,9 +1,12 @@
-// misc utility functions
+/* eslint-disable indent*/
+////////////////////////////
+// misc utility functions //
+////////////////////////////
function idInArray(id, arr) {
// because sometimes ids are strings and sometimes they're integers
- for (index in arr) {
- if (id.toString() == arr[index].toString()) {
+ for (var index in arr) {
+ if (id.toString() === arr[index].toString()) {
return true;
}
}
@@ -24,113 +27,140 @@
return s.charAt(0).toUpperCase() + s.slice(1);
}
-function toTitleCase(str)
-{
- return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
+function toTitleCase(str) {
+ return str.replace(/\w\S*/g, function(txt) {
+ return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
+ });
}
-function fieldNameToHumanReadable(str)
-{
- str = str.replace("_", " ");
+function fieldNameToHumanReadable(str) {
+ str = str.replace('_', ' ');
return toTitleCase(str);
}
// http://stackoverflow.com/questions/2117320/set-maximum-displayed-rows-count-for-html-table
function limitTableRows(tableSelector, maxRows) {
- var table = $(tableSelector)[0] //document.getElementById(tableId);
+ var table = $(tableSelector)[0]; //document.getElementById(tableId);
var wrapper = table.parentNode;
var rowsInTable = table.rows.length;
+
try {
var border = getComputedStyle(table.rows[0].cells[0], '').getPropertyValue('border-top-width');
+
border = border.replace('px', '') * 1;
- } catch (e) {
+ }
+ catch (e) {
var border = table.rows[0].cells[0].currentStyle.borderWidth;
- border = (border.replace('px', '') * 1) / 2;
+
+ border = border.replace('px', '') * 1 / 2;
}
var height = 0;
+
if (rowsInTable > maxRows) {
for (var i = 0; i < maxRows; i++) {
height += table.rows[i].clientHeight + border;
- //console.log("XXX " + height + " " + table.rows[i].clientHeight + " " + border);
+ //console.log('XXX ' + height + ' ' + table.rows[i].clientHeight + ' ' + border);
}
- wrapper.style.height = height + "px";
+ wrapper.style.height = height + 'px';
}
}
function validateField(validatorName, value, obj) {
- if (validatorName=="notBlank") {
- if ((value==undefined) || (value=="")) {
- return "can not be blank";
+ if (validatorName === 'notBlank') {
+ if (value === undefined || value === null || value === '') {
+ return 'can not be blank';
}
}
// if notBlank wasn't set, and the field is blank, then we can return
- if ((value==undefined) || (value=="")) {
+ if (value === undefined || value === null || value === '') {
return true;
}
-
+ /* eslint-disable default-case */
switch (validatorName) {
- case "url":
- if (! /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value)) {
- return "must be a valid url";
- }
- break;
+ case 'url':
+ if (! /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value)) {
+ return 'must be a valid url';
+ }
+ break;
- case "portspec":
- if (! $.trim(value).match(portlist_regexp())) {
- return "must be a valid portspec (example: 'tcp 123, udp 456-789')"
- }
- break;
+ case 'portspec':
+ if (! $.trim(value).match(portlist_regexp())) {
+ return 'must be a valid portspec (example: \'tcp 123, udp 456-789\')';
+ }
+ break;
+ // TODO test this before add
+ // default:
+ // return true;
+ // break;
+ /* eslint-enable default-case */
}
return true;
}
-function array_diff(a1, a2)
-{
- var a=[], diff=[];
- for(var i=0;i<a1.length;i++)
- a[a1[i]]=true;
- for(var i=0;i<a2.length;i++)
- if(a[a2[i]]) delete a[a2[i]];
- else a[a2[i]]=true;
- for(var k in a)
- diff.push(k);
- return diff;
+function array_diff(a1, a2) {
+ var a = [], diff = [];
+
+ for(var i = 0;i < a1.length;i++) {
+ a[a1[i]] = true;
+ }
+
+ for(var i = 0;i < a2.length;i++) {
+ if(a[a2[i]]) {
+ delete a[a2[i]];
+ }
+ else {
+ a[a2[i]] = true;
+ }
+ }
+
+ for(var k in a) {
+ // check that the property in not inherithed
+ if ({}.hasOwnProperty.call(a, k)) {
+ diff.push(k);
+ }
+ }
+
+ return diff;
}
-function array_subtract(a1, a2)
-{
- result=[]
- for (index in a1) {
- value = a1[index];
- if (!$.inArray(value, a2) >= 0) {
- result.push(value);
+function array_subtract(a1, a2) {
+ var result = [];
+
+ // why not for ... of, move to lodash instead
+ for (var index in a1) {
+ if ({}.hasOwnProperty.call(a1, index)) {
+ var value = a1[index];
+
+ if (!$.inArray(value, a2) >= 0) {
+ result.push(value);
+ }
}
+
}
return result;
}
-function array_same_elements(arr1, arr2)
-{
+function array_same_elements(arr1, arr2) {
// return true if arrays have same elements, even if order is different
- return ($(arr1).not(arr2).length == 0 && $(arr2).not(arr1).length == 0);
+ return $(arr1).not(arr2).length === 0 && $(arr2).not(arr1).length === 0;
}
-function array_pair_lookup(x, names, values)
-{
- for (index in values) {
- if (values[index] == x) {
+function array_pair_lookup(x, names, values) {
+ for (var index in values) {
+ if (values[index] === x) {
return names[index];
}
}
- return "object #" + x;
+ return 'object #' + x;
}
function all_options(selector) {
- el = $(selector);
- result = [];
- _.each(el.find("option"), function(option) {
+ var el = $(selector);
+ var result = [];
+
+ _.each(el.find('option'), function(option) {
result.push($(option).val());
});
return result;
@@ -138,77 +168,93 @@
function make_same_width(containerSelector, itemSelector) {
var maxWidth = 0;
- $(containerSelector).find(itemSelector).each( function(index) { maxWidth = Math.max(maxWidth, $(this).width()); });
- console.log(maxWidth);
- $(containerSelector).find(itemSelector).each( function(index) { $(this).width(maxWidth); });
+
+ $(containerSelector).find(itemSelector).each(function() {
+ maxWidth = Math.max(maxWidth, $(this).width());
+ });
+
+ $(containerSelector).find(itemSelector).each(function() {
+ $(this).width(maxWidth);
+ });
}
function strip_scripts(s) {
- var div = document.createElement('div');
- div.innerHTML = s;
- var scripts = div.getElementsByTagName('script');
- var i = scripts.length;
- while (i--) {
- scripts[i].parentNode.removeChild(scripts[i]);
- }
- return div.innerHTML;
- }
+ var div = document.createElement('div');
+
+ div.innerHTML = s;
+ var scripts = div.getElementsByTagName('script');
+ var i = scripts.length;
+
+ while (i--) {
+ scripts[i].parentNode.removeChild(scripts[i]);
+ }
+ return div.innerHTML;
+}
function parse_portlist(ports) {
- /* Support a list of ports in the format "protocol:port, protocol:port, ..."
+ /* Support a list of ports in the format 'protocol:port, protocol:port, ...'
examples:
tcp 123
tcp 123:133
tcp 123, tcp 124, tcp 125, udp 201, udp 202
- User can put either a "/" or a " " between protocol and ports
- Port ranges can be specified with "-" or ":"
+ User can put either a '/' or a ' ' between protocol and ports
+ Port ranges can be specified with '-' or ':'
This is a straightforward port of the code in core/models/network.py
*/
var nats = [];
+
if (ports) {
- parts = ports.split(",")
+ var parts = ports.split(',');
+ var parts2, protocol, first, last, portStr;
+
$.each(parts, function(index, part) {
part = $.trim(part);
- if (part.indexOf("/")>=0) {
- parts2 = part.split("/",2);
- protocol=parts2[0];
- ports=parts2[1];
- } else if (part.indexOf(" ")>=0) {
- parts2 = part.split(" ",2);
- protocol=parts2[0];
- ports=parts2[1];
- } else {
- throw 'malformed port specifier ' + part + ', format example: "tcp 123, tcp 201:206, udp 333"';
+ if (part.indexOf('/') >= 0) {
+ parts2 = part.split('/',2);
+
+ protocol = parts2[0];
+ ports = parts2[1];
+ }
+ else if (part.indexOf(' ') >= 0) {
+ parts2 = part.split(' ',2);
+ protocol = parts2[0];
+ ports = parts2[1];
+ }
+ else {
+ throw 'malformed port specifier ' +
+ part + ', format example: "tcp 123, tcp 201:206, udp 333"';
}
protocol = $.trim(protocol);
ports = $.trim(ports);
- if (protocol!="tcp" && protocol!="udp") {
+ if (protocol !== 'tcp' && protocol !== 'udp') {
throw 'unknown protocol ' + protocol;
}
- if (ports.indexOf("-")>=0) {
- parts2 = ports.split("-");
+ if (ports.indexOf('-') >= 0) {
+ parts2 = ports.split('-');
first = parseInt($.trim(parts2[0]));
last = parseInt($.trim(parts2[1]));
- portStr = first + ":" + last;
- } else if (ports.indexOf(":")>=0) {
- parts2 = ports.split(":");
+ portStr = first + ':' + last;
+ }
+ else if (ports.indexOf(':') >= 0) {
+ parts2 = ports.split(':');
first = parseInt($.trim(parts2[0]));
last = parseInt($.trim(parts2[1]));
- portStr = first + ":" + last;
- } else {
+ portStr = first + ':' + last;
+ }
+ else {
portStr = parseInt(ports).toString();
}
- nats.push( {l4_protocol: protocol, l4_port: portStr} );
+ nats.push({l4_protocol: protocol, l4_port: portStr});
}); /* end $.each(ports) */
}
- return nats
+ return nats;
}
function portlist_regexp() {
@@ -216,23 +262,32 @@
specifiers. Saved here in long form, in case we need to change it
in the future.
*/
+ var paren, whitespace, protocol,
+ protocolSlash, numbers, range,
+ protoPorts, protoPortsCommas,
+ numbersOrRange, portSpec, multiProtoPorts;
- paren = function(x) { return "(?:" + x + ")"; }
- whitespace = " *";
- protocol = paren("tcp|udp");
- protocolSlash = protocol + paren(whitespace + "|\/");
- numbers = paren("[0-9]+");
- range = paren(numbers + paren("-|:") + numbers);
- numbersOrRange = paren(numbers + "|" + range);
+ paren = function(x) {
+ return '(?:' + x + ')';
+ };
+
+ whitespace = ' *';
+ protocol = paren('tcp|udp');
+ protocolSlash = protocol + paren(whitespace + '|\/');
+ numbers = paren('[0-9]+');
+ range = paren(numbers + paren('-|:') + numbers);
+ numbersOrRange = paren(numbers + '|' + range);
protoPorts = paren(protocolSlash + numbersOrRange);
- protoPortsCommas = paren(paren(protoPorts + "," + whitespace)+"+");
+ protoPortsCommas = paren(paren(protoPorts + ',' + whitespace) + '+');
multiProtoPorts = paren(protoPortsCommas + protoPorts);
- portSpec = "^" + paren(protoPorts + "|" + multiProtoPorts) + "$";
+ portSpec = '^' + paren(protoPorts + '|' + multiProtoPorts) + '$';
return RegExp(portSpec);
}
function portlist_selftest() {
- r = portlist_regexp();
+ var r = portlist_regexp();
+
+/* eslint-disable quotes, max-len*/
assert(! "tcp".match(r), 'should not have matched: "tcp"');
assert("tcp 1".match(r), 'should have matched: "tcp 1"');
assert("tcp 123".match(r), 'should have matched: "tcp 123"');
@@ -248,7 +303,8 @@
assert("tcp 123, udp 456".match(r), 'should have matched: "tcp 123, udp 456"');
assert("tcp 123-45, udp 456".match(r), 'should have matched: "tcp 123-45, udp 456"');
assert("tcp 123-45, udp 456, tcp 11, tcp 22:45, udp 76, udp 47:49, udp 60-61".match(r), 'should have matched: "tcp 123-45, udp 456, tcp 11, tcp 22:45, udp 76, udp 47:49, udp 60-61"');
- return "done";
+ /* eslint-enable quotes, max-len*/
+ return 'done';
}
//portlist_selftest();
diff --git a/xos/core/xoslib/static/js/xoslib/xos-validators.js b/xos/core/xoslib/static/js/xoslib/xos-validators.js
index bbba624..ecee144 100644
--- a/xos/core/xoslib/static/js/xoslib/xos-validators.js
+++ b/xos/core/xoslib/static/js/xoslib/xos-validators.js
@@ -1,3 +1,5 @@
+/* eslint-disable quotes, no-undef, max-len, new-cap*/
+/* eslint indent: [2, 2]*/
function xos_get_validators() {
this.account = {"updated": [], "policed": [], "created": [], "deleted": [], "site": ["notBlank"], "lazy_blocked": [], "backend_register": ["notBlank"], "write_protect": [], "backend_status": ["notBlank"], "id": [], "no_sync": [], "enacted": []};
this.charge = {"updated": [], "slice": [], "policed": [], "created": [], "deleted": [], "amount": ["notBlank"], "object": ["notBlank"], "account": ["notBlank"], "kind": ["notBlank"], "lazy_blocked": [], "backend_register": ["notBlank"], "write_protect": [], "state": ["notBlank"], "coreHours": ["notBlank"], "invoice": [], "date": ["notBlank"], "backend_status": ["notBlank"], "id": [], "no_sync": [], "enacted": []};
@@ -64,3 +66,4 @@
this.userDashboardView = {"updated": [], "policed": [], "created": [], "deleted": [], "dashboardView": ["notBlank"], "lazy_blocked": [], "backend_register": ["notBlank"], "write_protect": [], "user": ["notBlank"], "backend_status": ["notBlank"], "order": ["notBlank"], "id": [], "no_sync": [], "enacted": []};
};
xosvalidators = new xos_get_validators();
+/* eslint-enable quotes, no-undef, max-len, new-cap*/
diff --git a/xos/core/xoslib/static/js/xoslib/xosHelper.js b/xos/core/xoslib/static/js/xoslib/xosHelper.js
index 54ecba5..cad242f 100644
--- a/xos/core/xoslib/static/js/xoslib/xosHelper.js
+++ b/xos/core/xoslib/static/js/xoslib/xosHelper.js
@@ -1,3 +1,4 @@
+/* eslint-disable */
HTMLView = Marionette.ItemView.extend({
render: function() {
this.$el.append(this.options.html);
@@ -1172,3 +1173,4 @@
return String(s).replace(/"/g,'"')
}
}
+/* eslint-enable */
\ No newline at end of file