From 5cf1741fe4c65753eb036196f816fccdfb57e572 Mon Sep 17 00:00:00 2001 From: Trapenok Victor Date: Wed, 18 Oct 2017 13:04:17 +1000 Subject: [PATCH 001/110] fixed bug with quotes in vars --- polemarch/static/js/libs/just-watch.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/polemarch/static/js/libs/just-watch.js b/polemarch/static/js/libs/just-watch.js index bc61effc..746ed32d 100644 --- a/polemarch/static/js/libs/just-watch.js +++ b/polemarch/static/js/libs/just-watch.js @@ -119,7 +119,7 @@ var justReactive = { justStrip:function(html) { var tmp = document.createElement("DIV"); - tmp.innerHTML = html; + tmp.innerHTML = html.replace(//g, '>'); return tmp.textContent || tmp.innerText || ""; }, @@ -630,8 +630,8 @@ var justReactive = { { var val = opt.callBack(this[opt.prop], opt.customData) if(val) - { - return " data-just-watch-"+id+" "+opt.attrName+"=\""+ justReactive.justStrip(val).replace(/\"/g, "\\\"") +"\""; + { + return " data-just-watch-"+id+" "+opt.attrName+"=\""+ justReactive.justStrip(val).replace(/"/g, '"') +"\""; } else { @@ -644,8 +644,8 @@ var justReactive = { console.log("bindAttr", opt.prop, val); var html = "" if(val) - { - html = " data-just-watch-"+id+"=\"true\" "+opt.attrName+"=\""+ justReactive.justStrip(val).replace(/\"/g, "\\\"") +"\""; + { + html = " data-just-watch-"+id+"=\"true\" "+opt.attrName+"=\""+ justReactive.justStrip(val).replace(/"/g, '"') +"\""; } else { From c18ba046c61820662e3763e95ba66bd8201316f2 Mon Sep 17 00:00:00 2001 From: Sergey Klyuykov Date: Wed, 18 Oct 2017 15:17:35 +1000 Subject: [PATCH 002/110] Update gitpython lib --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 6d749a19..81622fd5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,7 +17,7 @@ jsonfield==2.0.2 uWSGI==2.0.15 # Repo types -gitpython==2.1.6 +gitpython==2.1.7 # additional DB and cache connectors PyMySQL From 42116e95f92b6c446fd68d6b2bac9abcf5d730bb Mon Sep 17 00:00:00 2001 From: Trapenok Victor Date: Thu, 19 Oct 2017 11:53:54 +1000 Subject: [PATCH 003/110] tests for inventory import --- polemarch/static/js/libs/just-watch.js | 11 +- polemarch/static/js/pmInventories.js | 18 +- polemarch/static/js/tests/qUnitTest.js | 294 +++---------------------- 3 files changed, 55 insertions(+), 268 deletions(-) diff --git a/polemarch/static/js/libs/just-watch.js b/polemarch/static/js/libs/just-watch.js index 746ed32d..d93205a4 100644 --- a/polemarch/static/js/libs/just-watch.js +++ b/polemarch/static/js/libs/just-watch.js @@ -118,9 +118,14 @@ var justReactive = { */ justStrip:function(html) { - var tmp = document.createElement("DIV"); - tmp.innerHTML = html.replace(//g, '>'); - return tmp.textContent || tmp.innerText || ""; + if(typeof html != "string") + { + return ""; + } + + var tmp = document.createElement("DIV"); + tmp.innerHTML = html.replace(//g, '>'); + return tmp.textContent || tmp.innerText || ""; }, addMethod:function(setter, prop, method) diff --git a/polemarch/static/js/pmInventories.js b/polemarch/static/js/pmInventories.js index c613ba2f..439a1fd2 100644 --- a/polemarch/static/js/pmInventories.js +++ b/polemarch/static/js/pmInventories.js @@ -1179,4 +1179,20 @@ pmInventories.addSubHosts = function(item_id, hosts_ids) } }); return def.promise(); -} \ No newline at end of file +} + +pmInventories.validateGroupName = function(name) +{ + if(!name) + { + return false; + } + + if(/^[a-zA-Z0-9\-\._]*$/.test(name.toLowerCase())) + { + return true; + } + + return false; +} + diff --git a/polemarch/static/js/tests/qUnitTest.js b/polemarch/static/js/tests/qUnitTest.js index 4f3e6805..ef669599 100644 --- a/polemarch/static/js/tests/qUnitTest.js +++ b/polemarch/static/js/tests/qUnitTest.js @@ -1280,232 +1280,7 @@ os-controller-2.vst.lan ansible_host=10.20.0.8 }) }); - var etalon = { - "hosts": [ - { - "name": "1.2.3.[1:255]", - "type": "RANGE", - "vars": { - - } - }, - { - "name": "124.3.4.[44:55]", - "type": "RANGE", - "vars": { - - } - }, - { - "name": "124.3.5.[1:250]", - "type": "RANGE", - "vars": { - "ansible_host": "10.20.0.2", - "ansible_user": "root", - "ansible_ssh_pass": "eadgbe", - "ansible_ssh_private_key_file": "/root/f.txt" - } - }, - { - "name": "124.3.5.[1:251]", - "type": "RANGE", - "vars": { - "ansible_host": "10.20.0.2", - "ansible_user": "root", - "ansible_ssh_pass": "eadgbe" - } - }, - { - "name": "124.3.5.[1:252]", - "type": "RANGE", - "vars": { - "ansible_host": "10.20.0.12", - "ansible_user": "r\"o\\'ot", - "ansible_ssh_pass": "eadgbe" - } - } - ], - "groups": { - "git": { - "vars": { - - }, - "groups": [ - "ci", - "git-servers" - ], - "hosts": [ - - ], - "children": true - }, - "cloud": { - "vars": { - - }, - "groups": [ - "git", - "services", - "test" - ], - "hosts": [ - - ], - "children": true - }, - "test": { - "vars": { - "ansible_ssh_private_key_file": "/root/f.txt" - }, - "groups": [ - - ], - "hosts": [ - { - "name": "test.vst.lan", - "type": "HOST", - "vars": { - "ansible_user": "centos" - } - }, - { - "name": "test2.vst.lan", - "type": "HOST", - "vars": { - "ansible_host": "172.16.1.26" - } - } - ] - }, - "ci": { - "vars": { - - }, - "groups": [ - - ], - "hosts": [ - { - "name": "git-ci-1", - "type": "HOST", - "vars": { - "ansible_host": "172.16.1.13", - "ansible_ssh_private_key_file": "/root/f.txt" - } - }, - { - "name": "git-ci-2", - "type": "HOST", - "vars": { - "ansible_host": "172.16.1.14" - } - } - ] - }, - "git-servers": { - "vars": { - - }, - "groups": [ - - ], - "hosts": [ - { - "name": "git.vst.lan", - "type": "HOST", - "vars": { - - } - } - ] - }, - "services": { - "vars": { - - }, - "groups": [ - - ], - "hosts": [ - { - "name": "chat.vstconsulting.net", - "type": "HOST", - "vars": { - "ansible_host": "172.16.1.16" - } - }, - { - "name": "pipc.vst.lan", - "type": "HOST", - "vars": { - - } - }, - { - "name": "redmine.vst.lan", - "type": "HOST", - "vars": { - - } - } - ] - }, - "openstack": { - "vars": { - - }, - "groups": [ - - ], - "hosts": [ - { - "name": "fuel.vst.lan", - "type": "HOST", - "vars": { - "ansible_host": "10.20.0.2", - "ansible_user": "root", - "ansible_ssh_pass": "eadgbe" - } - }, - { - "name": "os-compute-1.vst.lan", - "type": "HOST", - "vars": { - "ansible_host": "10.20.0.9" - } - }, - { - "name": "os-compute-2.vst.lan", - "type": "HOST", - "vars": { - "ansible_host": "10.20.0.13", - "ansible_ssh_private_key_file": "/root/f.txt" - } - }, - { - "name": "os-controller-1.vst.lan", - "type": "HOST", - "vars": { - "ansible_host": "10.20.0.6" - } - }, - { - "name": "os-controller-2.vst.lan", - "type": "HOST", - "vars": { - "ansible_host": "10.20.0.8" - } - } - ] - } - }, - "vars": { - "ansible_user": "grey", - "ansible_ssh_private_key_file": "/root/f.txt", - "ansible_ssh_extra_args": "-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" - }, - name : "inventory", - } + var etalon = {"hosts":[{"name":"1.2.3.[1:255]","type":"RANGE","vars":{}},{"name":"124.3.4.[44:55]","type":"RANGE","vars":{}},{"name":"124.3.5.[1:250]","type":"RANGE","vars":{"ansible_host":"10.20.0.2","ansible_user":"root","ansible_ssh_pass":"eadgbe","ansible_ssh_private_key_file":"/root/f.txt"}},{"name":"124.3.5.[1:251]","type":"RANGE","vars":{"ansible_host":"10.20.0.2","ansible_user":"root","ansible_ssh_pass":"eadgbe"}},{"name":"124.3.5.[1:252]","type":"RANGE","vars":{"ansible_host":"10.20.0.12","ansible_user":"r\"o\\'ot","ansible_ssh_pass":"eadgbe"}}],"groups":{"git":{"vars":{},"groups":["ci","git-servers"],"hosts":[],"children":true,"dataLevel":{"level":2,"parents":["all","cloud","git"]}},"ci":{"vars":{},"groups":[],"hosts":[{"name":"git-ci-1","type":"HOST","vars":{"ansible_host":"172.16.1.13","ansible_ssh_private_key_file":"/root/f.txt"}},{"name":"git-ci-2","type":"HOST","vars":{"ansible_host":"172.16.1.14"}}],"dataLevel":{"level":3,"parents":["all","cloud","git","ci"]}},"git-servers":{"vars":{},"groups":[],"hosts":[{"name":"git.vst.lan","type":"HOST","vars":{}}],"dataLevel":{"level":3,"parents":["all","cloud","git","git-servers"]}},"cloud":{"vars":{},"groups":["git","services","test"],"hosts":[],"children":true,"dataLevel":{"level":1,"parents":["all","cloud"]}},"services":{"vars":{},"groups":[],"hosts":[{"name":"chat.vstconsulting.net","type":"HOST","vars":{"ansible_host":"172.16.1.16"}},{"name":"pipc.vst.lan","type":"HOST","vars":{}},{"name":"redmine.vst.lan","type":"HOST","vars":{}}],"dataLevel":{"level":2,"parents":["all","cloud","services"]}},"test":{"vars":{"ansible_ssh_private_key_file":"/root/f.txt"},"groups":[],"hosts":[{"name":"test.vst.lan","type":"HOST","vars":{"ansible_user":"centos"}},{"name":"test2.vst.lan","type":"HOST","vars":{"ansible_host":"172.16.1.26"}}],"dataLevel":{"level":2,"parents":["all","cloud","test"]}},"openstack":{"vars":{},"groups":[],"hosts":[{"name":"fuel.vst.lan","type":"HOST","vars":{"ansible_host":"10.20.0.2","ansible_user":"root","ansible_ssh_pass":"eadgbe"}},{"name":"os-compute-1.vst.lan","type":"HOST","vars":{"ansible_host":"10.20.0.9"}},{"name":"os-compute-2.vst.lan","type":"HOST","vars":{"ansible_host":"10.20.0.13","ansible_ssh_private_key_file":"/root/f.txt"}},{"name":"os-controller-1.vst.lan","type":"HOST","vars":{"ansible_host":"10.20.0.6"}},{"name":"os-controller-2.vst.lan","type":"HOST","vars":{"ansible_host":"10.20.0.8"}}],"dataLevel":{"level":1,"parents":["all","openstack"]}}},"vars":{"ansible_user":"grey","ansible_ssh_private_key_file":"/root/f.txt","ansible_ssh_extra_args":"-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"},"name":"inventory"} var inventory = undefined; syncQUnit.addTest('Парсинг inventory', function ( assert ) @@ -1518,7 +1293,7 @@ os-controller-2.vst.lan ansible_host=10.20.0.8 inventory:inventory, text:pmInventoriesText } - + var res = deepEqual(etalon, inventory) assert.ok(res, 'Сравнение инвентория распарсенного и оригинального'); render(done) @@ -1614,47 +1389,38 @@ G9zCmFuc2libGVfc3NoX3ByaXZhdGVfa2V5X2ZpbGU9L2hvbWUvY2VwcmV1L2RlZmF1bHQucGVtCmFu\ c2libGVfYmVjb21lPXRydWU=" inventoryText = Base64.decode(inventoryText) - var inventory = pmInventories.parseFromText(inventoryText) + inventory = pmInventories.parseFromText(inventoryText) var etalon = { - "hosts": [], - "groups": { - "servers": { - "vars": { - "ansible_user": "centos", - "ansible_ssh_private_key_file": "/home/cepreu/default.pem", - "ansible_become": "true" + "hosts":[], + "groups":{ + "servers":{ + "vars":{"ansible_user":"centos","ansible_ssh_private_key_file":"/home/cepreu/default.pem","ansible_become":"true"}, + "groups":["usual","unusual"], + "hosts":[], + "children":true, + "dataLevel":{"level":1,"parents":["all","servers"]} }, - "groups": [ - "usual", - "unusual" - ], - "hosts": [], - "children": true - }, - "usual": { - "vars": {}, - "groups": [], - "hosts": [ - { - "name": "172.16.1.[30:31]", - "type": "RANGE", - "vars": { - - } - } - ] - }, - "unusual": { - "vars": {}, - "groups": [], - "hosts": [] - } + "usual":{ + "vars":{}, + "groups":[], + "hosts":[ + {"name":"172.16.1.[30:31]","type":"RANGE","vars":{}} + ], + "dataLevel":{"level":2,"parents":["all","servers","usual"]} + }, + "unusual":{ + "vars":{}, + "groups":[], + "hosts":[], + "dataLevel":{"level":2,"parents":["all","servers","unusual"]} + } }, - "vars": {}, - name:"inventory" - } + "vars":{}, + "name":"inventory" + } + inventory.name = "inventory" - + var res = deepEqual(etalon, inventory) assert.ok(res, 'Сравнение инвентория 2 распарсенного и оригинального'); render(done) From ef4a00e745578e2bbcd2098098b75d2c763c1b8f Mon Sep 17 00:00:00 2001 From: Trapenok Victor Date: Thu, 19 Oct 2017 13:05:40 +1000 Subject: [PATCH 004/110] tests refactoring --- polemarch/main/templates/base.html | 2 +- polemarch/main/templates/gui/gui.html | 1 + polemarch/static/js/app.js | 55 +--- polemarch/static/js/common.js | 14 + polemarch/static/js/demo.js | 340 ------------------------ polemarch/static/js/pages/dashboard.js | 210 --------------- polemarch/static/js/pages/dashboard2.js | 274 ------------------- polemarch/static/js/tests/qUnitTest.js | 80 +++--- 8 files changed, 61 insertions(+), 915 deletions(-) create mode 100644 polemarch/static/js/common.js delete mode 100644 polemarch/static/js/demo.js delete mode 100644 polemarch/static/js/pages/dashboard.js delete mode 100644 polemarch/static/js/pages/dashboard2.js diff --git a/polemarch/main/templates/base.html b/polemarch/main/templates/base.html index 8628e085..c431dd32 100644 --- a/polemarch/main/templates/base.html +++ b/polemarch/main/templates/base.html @@ -176,7 +176,7 @@ {% endif %} diff --git a/polemarch/main/templates/gui/gui.html b/polemarch/main/templates/gui/gui.html index fe5dd760..1e215ddb 100644 --- a/polemarch/main/templates/gui/gui.html +++ b/polemarch/main/templates/gui/gui.html @@ -18,6 +18,7 @@ + diff --git a/polemarch/static/js/app.js b/polemarch/static/js/app.js index 2ce0bdd6..b34dbd83 100644 --- a/polemarch/static/js/app.js +++ b/polemarch/static/js/app.js @@ -716,57 +716,4 @@ function _init() { }; })(jQuery); - -/* - * TODO LIST CUSTOM PLUGIN - * ----------------------- - * This plugin depends on iCheck plugin for checkbox and radio inputs - * - * @type plugin - * @usage $("#todo-widget").todolist( options ); - */ -(function ($) { - - 'use strict'; - - $.fn.todolist = function (options) { - // Render options - var settings = $.extend({ - //When the user checks the input - onCheck: function (ele) { - return ele; - }, - //When the user unchecks the input - onUncheck: function (ele) { - return ele; - } - }, options); - - return this.each(function () { - - if (typeof $.fn.iCheck != 'undefined') { - $('input', this).on('ifChecked', function () { - var ele = $(this).parents("li").first(); - ele.toggleClass("done"); - settings.onCheck.call(ele); - }); - - $('input', this).on('ifUnchecked', function () { - var ele = $(this).parents("li").first(); - ele.toggleClass("done"); - settings.onUncheck.call(ele); - }); - } else { - $('input', this).on('change', function () { - var ele = $(this).parents("li").first(); - ele.toggleClass("done"); - if ($('input', ele).is(":checked")) { - settings.onCheck.call(ele); - } else { - settings.onUncheck.call(ele); - } - }); - } - }); - }; -}(jQuery)); + \ No newline at end of file diff --git a/polemarch/static/js/common.js b/polemarch/static/js/common.js new file mode 100644 index 00000000..b8720d1f --- /dev/null +++ b/polemarch/static/js/common.js @@ -0,0 +1,14 @@ +function loadQUnitTests() +{ + + $('body').append(''); + + var intervaId = setInterval(function() + { + if(window.injectQunit !== undefined) + { + clearInterval(intervaId) + injectQunit() + } + }, 1000) +} \ No newline at end of file diff --git a/polemarch/static/js/demo.js b/polemarch/static/js/demo.js deleted file mode 100644 index b18b9bb3..00000000 --- a/polemarch/static/js/demo.js +++ /dev/null @@ -1,340 +0,0 @@ -/** - * AdminLTE Demo Menu - * ------------------ - * You should not use this file in production. - * This file is for demo purposes only. - */ -(function ($, AdminLTE) { - - "use strict"; - - /** - * List of all the available skins - * - * @type Array - */ - var my_skins = [ - "skin-blue", - "skin-black", - "skin-red", - "skin-yellow", - "skin-purple", - "skin-green", - "skin-blue-light", - "skin-black-light", - "skin-red-light", - "skin-yellow-light", - "skin-purple-light", - "skin-green-light" - ]; - - //Create the new tab - var tab_pane = $("
", { - "id": "control-sidebar-theme-demo-options-tab", - "class": "tab-pane active" - }); - - //Create the tab button - var tab_button = $("
  • ", {"class": "active"}) - .html("" - + "" - + ""); - - //Add the tab button to the right sidebar tabs - $("[href='#control-sidebar-home-tab']") - .parent() - .before(tab_button); - - //Create the menu - var demo_settings = $("
    "); - - //Layout options - demo_settings.append( - "

    " - + "Layout Options" - + "

    " - //Fixed layout - + "
    " - + "" - + "

    Activate the fixed layout. You can't use fixed and boxed layouts together

    " - + "
    " - //Boxed layout - + "
    " - + "" - + "

    Activate the boxed layout

    " - + "
    " - //Sidebar Toggle - + "
    " - + "" - + "

    Toggle the left sidebar's state (open or collapse)

    " - + "
    " - //Sidebar mini expand on hover toggle - + "
    " - + "" - + "

    Let the sidebar mini expand on hover

    " - + "
    " - //Control Sidebar Toggle - + "
    " - + "" - + "

    Toggle between slide over content and push content effects

    " - + "
    " - //Control Sidebar Skin Toggle - + "
    " - + "" - + "

    Toggle between dark and light skins for the right sidebar

    " - + "
    " - ); - var skins_list = $("
      ", {"class": 'list-unstyled clearfix'}); - - //Dark sidebar skins - var skin_blue = - $("
    • ", {style: "float:left; width: 33.33333%; padding: 5px;"}) - .append("" - + "
      " - + "
      " - + "
      " - + "

      Blue

      "); - skins_list.append(skin_blue); - var skin_black = - $("
    • ", {style: "float:left; width: 33.33333%; padding: 5px;"}) - .append("" - + "
      " - + "
      " - + "
      " - + "

      Black

      "); - skins_list.append(skin_black); - var skin_purple = - $("
    • ", {style: "float:left; width: 33.33333%; padding: 5px;"}) - .append("" - + "
      " - + "
      " - + "
      " - + "

      Purple

      "); - skins_list.append(skin_purple); - var skin_green = - $("
    • ", {style: "float:left; width: 33.33333%; padding: 5px;"}) - .append("" - + "
      " - + "
      " - + "
      " - + "

      Green

      "); - skins_list.append(skin_green); - var skin_red = - $("
    • ", {style: "float:left; width: 33.33333%; padding: 5px;"}) - .append("" - + "
      " - + "
      " - + "
      " - + "

      Red

      "); - skins_list.append(skin_red); - var skin_yellow = - $("
    • ", {style: "float:left; width: 33.33333%; padding: 5px;"}) - .append("" - + "
      " - + "
      " - + "
      " - + "

      Yellow

      "); - skins_list.append(skin_yellow); - - //Light sidebar skins - var skin_blue_light = - $("
    • ", {style: "float:left; width: 33.33333%; padding: 5px;"}) - .append("" - + "
      " - + "
      " - + "
      " - + "

      Blue Light

      "); - skins_list.append(skin_blue_light); - var skin_black_light = - $("
    • ", {style: "float:left; width: 33.33333%; padding: 5px;"}) - .append("" - + "
      " - + "
      " - + "
      " - + "

      Black Light

      "); - skins_list.append(skin_black_light); - var skin_purple_light = - $("
    • ", {style: "float:left; width: 33.33333%; padding: 5px;"}) - .append("" - + "
      " - + "
      " - + "
      " - + "

      Purple Light

      "); - skins_list.append(skin_purple_light); - var skin_green_light = - $("
    • ", {style: "float:left; width: 33.33333%; padding: 5px;"}) - .append("" - + "
      " - + "
      " - + "
      " - + "

      Green Light

      "); - skins_list.append(skin_green_light); - var skin_red_light = - $("
    • ", {style: "float:left; width: 33.33333%; padding: 5px;"}) - .append("" - + "
      " - + "
      " - + "
      " - + "

      Red Light

      "); - skins_list.append(skin_red_light); - var skin_yellow_light = - $("
    • ", {style: "float:left; width: 33.33333%; padding: 5px;"}) - .append("" - + "
      " - + "
      " - + "
      " - + "

      Yellow Light

      "); - skins_list.append(skin_yellow_light); - - demo_settings.append("

      Skins

      "); - demo_settings.append(skins_list); - - tab_pane.append(demo_settings); - $("#control-sidebar-home-tab").after(tab_pane); - - setup(); - - /** - * Toggles layout classes - * - * @param String cls the layout class to toggle - * @returns void - */ - function change_layout(cls) { - $("body").toggleClass(cls); - AdminLTE.layout.fixSidebar(); - //Fix the problem with right sidebar and layout boxed - if (cls == "layout-boxed") - AdminLTE.controlSidebar._fix($(".control-sidebar-bg")); - if ($('body').hasClass('fixed') && cls == 'fixed') { - AdminLTE.pushMenu.expandOnHover(); - AdminLTE.layout.activate(); - } - AdminLTE.controlSidebar._fix($(".control-sidebar-bg")); - AdminLTE.controlSidebar._fix($(".control-sidebar")); - } - - /** - * Replaces the old skin with the new skin - * @param String cls the new skin class - * @returns Boolean false to prevent link's default action - */ - function change_skin(cls) { - $.each(my_skins, function (i) { - $("body").removeClass(my_skins[i]); - }); - - $("body").addClass(cls); - store('skin', cls); - return false; - } - - /** - * Store a new settings in the browser - * - * @param String name Name of the setting - * @param String val Value of the setting - * @returns void - */ - function store(name, val) { - if (typeof (Storage) !== "undefined") { - localStorage.setItem(name, val); - } else { - window.alert('Please use a modern browser to properly view this template!'); - } - } - - /** - * Get a prestored setting - * - * @param String name Name of of the setting - * @returns String The value of the setting | null - */ - function get(name) { - if (typeof (Storage) !== "undefined") { - return localStorage.getItem(name); - } else { - window.alert('Please use a modern browser to properly view this template!'); - } - } - - /** - * Retrieve default settings and apply them to the template - * - * @returns void - */ - function setup() { - var tmp = get('skin'); - if (tmp && $.inArray(tmp, my_skins)) - change_skin(tmp); - - //Add the change skin listener - $("[data-skin]").on('click', function (e) { - if($(this).hasClass('knob')) - return; - e.preventDefault(); - change_skin($(this).data('skin')); - }); - - //Add the layout manager - $("[data-layout]").on('click', function () { - change_layout($(this).data('layout')); - }); - - $("[data-controlsidebar]").on('click', function () { - change_layout($(this).data('controlsidebar')); - var slide = !AdminLTE.options.controlSidebarOptions.slide; - AdminLTE.options.controlSidebarOptions.slide = slide; - if (!slide) - $('.control-sidebar').removeClass('control-sidebar-open'); - }); - - $("[data-sidebarskin='toggle']").on('click', function () { - var sidebar = $(".control-sidebar"); - if (sidebar.hasClass("control-sidebar-dark")) { - sidebar.removeClass("control-sidebar-dark") - sidebar.addClass("control-sidebar-light") - } else { - sidebar.removeClass("control-sidebar-light") - sidebar.addClass("control-sidebar-dark") - } - }); - - $("[data-enable='expandOnHover']").on('click', function () { - $(this).attr('disabled', true); - AdminLTE.pushMenu.expandOnHover(); - if (!$('body').hasClass('sidebar-collapse')) - $("[data-layout='sidebar-collapse']").click(); - }); - - // Reset options - if ($('body').hasClass('fixed')) { - $("[data-layout='fixed']").attr('checked', 'checked'); - } - if ($('body').hasClass('layout-boxed')) { - $("[data-layout='layout-boxed']").attr('checked', 'checked'); - } - if ($('body').hasClass('sidebar-collapse')) { - $("[data-layout='sidebar-collapse']").attr('checked', 'checked'); - } - - } -})(jQuery, $.AdminLTE); diff --git a/polemarch/static/js/pages/dashboard.js b/polemarch/static/js/pages/dashboard.js deleted file mode 100644 index 0f7c0077..00000000 --- a/polemarch/static/js/pages/dashboard.js +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Author: Abdullah A Almsaeed - * Date: 4 Jan 2014 - * Description: - * This is a demo file used only for the main dashboard (index.html) - **/ - -$(function () { - - "use strict"; - - //Make the dashboard widgets sortable Using jquery UI - $(".connectedSortable").sortable({ - placeholder: "sort-highlight", - connectWith: ".connectedSortable", - handle: ".box-header, .nav-tabs", - forcePlaceholderSize: true, - zIndex: 999999 - }); - $(".connectedSortable .box-header, .connectedSortable .nav-tabs-custom").css("cursor", "move"); - - //jQuery UI sortable for the todo list - $(".todo-list").sortable({ - placeholder: "sort-highlight", - handle: ".handle", - forcePlaceholderSize: true, - zIndex: 999999 - }); - - //bootstrap WYSIHTML5 - text editor - $(".textarea").wysihtml5(); - - $('.daterange').daterangepicker({ - ranges: { - 'Today': [moment(), moment()], - 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')], - 'Last 7 Days': [moment().subtract(6, 'days'), moment()], - 'Last 30 Days': [moment().subtract(29, 'days'), moment()], - 'This Month': [moment().startOf('month'), moment().endOf('month')], - 'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')] - }, - startDate: moment().subtract(29, 'days'), - endDate: moment() - }, function (start, end) { - window.alert("You chose: " + start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY')); - }); - - /* jQueryKnob */ - $(".knob").knob(); - - //jvectormap data - var visitorsData = { - "US": 398, //USA - "SA": 400, //Saudi Arabia - "CA": 1000, //Canada - "DE": 500, //Germany - "FR": 760, //France - "CN": 300, //China - "AU": 700, //Australia - "BR": 600, //Brazil - "IN": 800, //India - "GB": 320, //Great Britain - "RU": 3000 //Russia - }; - //World map by jvectormap - $('#world-map').vectorMap({ - map: 'world_mill_en', - backgroundColor: "transparent", - regionStyle: { - initial: { - fill: '#e4e4e4', - "fill-opacity": 1, - stroke: 'none', - "stroke-width": 0, - "stroke-opacity": 1 - } - }, - series: { - regions: [{ - values: visitorsData, - scale: ["#92c1dc", "#ebf4f9"], - normalizeFunction: 'polynomial' - }] - }, - onRegionLabelShow: function (e, el, code) { - if (typeof visitorsData[code] != "undefined") - el.html(el.html() + ': ' + visitorsData[code] + ' new visitors'); - } - }); - - //Sparkline charts - var myvalues = [1000, 1200, 920, 927, 931, 1027, 819, 930, 1021]; - $('#sparkline-1').sparkline(myvalues, { - type: 'line', - lineColor: '#92c1dc', - fillColor: "#ebf4f9", - height: '50', - width: '80' - }); - myvalues = [515, 519, 520, 522, 652, 810, 370, 627, 319, 630, 921]; - $('#sparkline-2').sparkline(myvalues, { - type: 'line', - lineColor: '#92c1dc', - fillColor: "#ebf4f9", - height: '50', - width: '80' - }); - myvalues = [15, 19, 20, 22, 33, 27, 31, 27, 19, 30, 21]; - $('#sparkline-3').sparkline(myvalues, { - type: 'line', - lineColor: '#92c1dc', - fillColor: "#ebf4f9", - height: '50', - width: '80' - }); - - //The Calender - $("#calendar").datepicker(); - - //SLIMSCROLL FOR CHAT WIDGET - $('#chat-box').slimScroll({ - height: '250px' - }); - - /* Morris.js Charts */ - // Sales chart - var area = new Morris.Area({ - element: 'revenue-chart', - resize: true, - data: [ - {y: '2011 Q1', item1: 2666, item2: 2666}, - {y: '2011 Q2', item1: 2778, item2: 2294}, - {y: '2011 Q3', item1: 4912, item2: 1969}, - {y: '2011 Q4', item1: 3767, item2: 3597}, - {y: '2012 Q1', item1: 6810, item2: 1914}, - {y: '2012 Q2', item1: 5670, item2: 4293}, - {y: '2012 Q3', item1: 4820, item2: 3795}, - {y: '2012 Q4', item1: 15073, item2: 5967}, - {y: '2013 Q1', item1: 10687, item2: 4460}, - {y: '2013 Q2', item1: 8432, item2: 5713} - ], - xkey: 'y', - ykeys: ['item1', 'item2'], - labels: ['Item 1', 'Item 2'], - lineColors: ['#a0d0e0', '#3c8dbc'], - hideHover: 'auto' - }); - var line = new Morris.Line({ - element: 'line-chart', - resize: true, - data: [ - {y: '2011 Q1', item1: 2666}, - {y: '2011 Q2', item1: 2778}, - {y: '2011 Q3', item1: 4912}, - {y: '2011 Q4', item1: 3767}, - {y: '2012 Q1', item1: 6810}, - {y: '2012 Q2', item1: 5670}, - {y: '2012 Q3', item1: 4820}, - {y: '2012 Q4', item1: 15073}, - {y: '2013 Q1', item1: 10687}, - {y: '2013 Q2', item1: 8432} - ], - xkey: 'y', - ykeys: ['item1'], - labels: ['Item 1'], - lineColors: ['#efefef'], - lineWidth: 2, - hideHover: 'auto', - gridTextColor: "#fff", - gridStrokeWidth: 0.4, - pointSize: 4, - pointStrokeColors: ["#efefef"], - gridLineColor: "#efefef", - gridTextFamily: "Open Sans", - gridTextSize: 10 - }); - - //Donut Chart - var donut = new Morris.Donut({ - element: 'sales-chart', - resize: true, - colors: ["#3c8dbc", "#f56954", "#00a65a"], - data: [ - {label: "Download Sales", value: 12}, - {label: "In-Store Sales", value: 30}, - {label: "Mail-Order Sales", value: 20} - ], - hideHover: 'auto' - }); - - //Fix for charts under tabs - $('.box ul.nav a').on('shown.bs.tab', function () { - area.redraw(); - donut.redraw(); - line.redraw(); - }); - - /* The todo list plugin */ - $(".todo-list").todolist({ - onCheck: function (ele) { - window.console.log("The element has been checked"); - return ele; - }, - onUncheck: function (ele) { - window.console.log("The element has been unchecked"); - return ele; - } - }); - -}); diff --git a/polemarch/static/js/pages/dashboard2.js b/polemarch/static/js/pages/dashboard2.js deleted file mode 100644 index cc67785e..00000000 --- a/polemarch/static/js/pages/dashboard2.js +++ /dev/null @@ -1,274 +0,0 @@ -$(function () { - - 'use strict'; - - /* ChartJS - * ------- - * Here we will create a few charts using ChartJS - */ - - //----------------------- - //- MONTHLY SALES CHART - - //----------------------- - - // Get context with jQuery - using jQuery's .get() method. - var salesChartCanvas = $("#salesChart").get(0).getContext("2d"); - // This will get the first returned node in the jQuery collection. - var salesChart = new Chart(salesChartCanvas); - - var salesChartData = { - labels: ["January", "February", "March", "April", "May", "June", "July"], - datasets: [ - { - label: "Electronics", - fillColor: "rgb(210, 214, 222)", - strokeColor: "rgb(210, 214, 222)", - pointColor: "rgb(210, 214, 222)", - pointStrokeColor: "#c1c7d1", - pointHighlightFill: "#fff", - pointHighlightStroke: "rgb(220,220,220)", - data: [65, 59, 80, 81, 56, 55, 40] - }, - { - label: "Digital Goods", - fillColor: "rgba(60,141,188,0.9)", - strokeColor: "rgba(60,141,188,0.8)", - pointColor: "#3b8bba", - pointStrokeColor: "rgba(60,141,188,1)", - pointHighlightFill: "#fff", - pointHighlightStroke: "rgba(60,141,188,1)", - data: [28, 48, 40, 19, 86, 27, 90] - } - ] - }; - - var salesChartOptions = { - //Boolean - If we should show the scale at all - showScale: true, - //Boolean - Whether grid lines are shown across the chart - scaleShowGridLines: false, - //String - Colour of the grid lines - scaleGridLineColor: "rgba(0,0,0,.05)", - //Number - Width of the grid lines - scaleGridLineWidth: 1, - //Boolean - Whether to show horizontal lines (except X axis) - scaleShowHorizontalLines: true, - //Boolean - Whether to show vertical lines (except Y axis) - scaleShowVerticalLines: true, - //Boolean - Whether the line is curved between points - bezierCurve: true, - //Number - Tension of the bezier curve between points - bezierCurveTension: 0.3, - //Boolean - Whether to show a dot for each point - pointDot: false, - //Number - Radius of each point dot in pixels - pointDotRadius: 4, - //Number - Pixel width of point dot stroke - pointDotStrokeWidth: 1, - //Number - amount extra to add to the radius to cater for hit detection outside the drawn point - pointHitDetectionRadius: 20, - //Boolean - Whether to show a stroke for datasets - datasetStroke: true, - //Number - Pixel width of dataset stroke - datasetStrokeWidth: 2, - //Boolean - Whether to fill the dataset with a color - datasetFill: true, - //String - A legend template - legendTemplate: "
        -legend\"><% for (var i=0; i
      • \"><%=datasets[i].label%>
      • <%}%>
      ", - //Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container - maintainAspectRatio: true, - //Boolean - whether to make the chart responsive to window resizing - responsive: true - }; - - //Create the line chart - salesChart.Line(salesChartData, salesChartOptions); - - //--------------------------- - //- END MONTHLY SALES CHART - - //--------------------------- - - //------------- - //- PIE CHART - - //------------- - // Get context with jQuery - using jQuery's .get() method. - var pieChartCanvas = $("#pieChart").get(0).getContext("2d"); - var pieChart = new Chart(pieChartCanvas); - var PieData = [ - { - value: 700, - color: "#f56954", - highlight: "#f56954", - label: "Chrome" - }, - { - value: 500, - color: "#00a65a", - highlight: "#00a65a", - label: "IE" - }, - { - value: 400, - color: "#f39c12", - highlight: "#f39c12", - label: "FireFox" - }, - { - value: 600, - color: "#00c0ef", - highlight: "#00c0ef", - label: "Safari" - }, - { - value: 300, - color: "#3c8dbc", - highlight: "#3c8dbc", - label: "Opera" - }, - { - value: 100, - color: "#d2d6de", - highlight: "#d2d6de", - label: "Navigator" - } - ]; - var pieOptions = { - //Boolean - Whether we should show a stroke on each segment - segmentShowStroke: true, - //String - The colour of each segment stroke - segmentStrokeColor: "#fff", - //Number - The width of each segment stroke - segmentStrokeWidth: 1, - //Number - The percentage of the chart that we cut out of the middle - percentageInnerCutout: 50, // This is 0 for Pie charts - //Number - Amount of animation steps - animationSteps: 100, - //String - Animation easing effect - animationEasing: "easeOutBounce", - //Boolean - Whether we animate the rotation of the Doughnut - animateRotate: true, - //Boolean - Whether we animate scaling the Doughnut from the centre - animateScale: false, - //Boolean - whether to make the chart responsive to window resizing - responsive: true, - // Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container - maintainAspectRatio: false, - //String - A legend template - legendTemplate: "
        -legend\"><% for (var i=0; i
      • \"><%if(segments[i].label){%><%=segments[i].label%><%}%>
      • <%}%>
      ", - //String - A tooltip template - tooltipTemplate: "<%=value %> <%=label%> users" - }; - //Create pie or douhnut chart - // You can switch between pie and douhnut using the method below. - pieChart.Doughnut(PieData, pieOptions); - //----------------- - //- END PIE CHART - - //----------------- - - /* jVector Maps - * ------------ - * Create a world map with markers - */ - $('#world-map-markers').vectorMap({ - map: 'world_mill_en', - normalizeFunction: 'polynomial', - hoverOpacity: 0.7, - hoverColor: false, - backgroundColor: 'transparent', - regionStyle: { - initial: { - fill: 'rgba(210, 214, 222, 1)', - "fill-opacity": 1, - stroke: 'none', - "stroke-width": 0, - "stroke-opacity": 1 - }, - hover: { - "fill-opacity": 0.7, - cursor: 'pointer' - }, - selected: { - fill: 'yellow' - }, - selectedHover: {} - }, - markerStyle: { - initial: { - fill: '#00a65a', - stroke: '#111' - } - }, - markers: [ - {latLng: [41.90, 12.45], name: 'Vatican City'}, - {latLng: [43.73, 7.41], name: 'Monaco'}, - {latLng: [-0.52, 166.93], name: 'Nauru'}, - {latLng: [-8.51, 179.21], name: 'Tuvalu'}, - {latLng: [43.93, 12.46], name: 'San Marino'}, - {latLng: [47.14, 9.52], name: 'Liechtenstein'}, - {latLng: [7.11, 171.06], name: 'Marshall Islands'}, - {latLng: [17.3, -62.73], name: 'Saint Kitts and Nevis'}, - {latLng: [3.2, 73.22], name: 'Maldives'}, - {latLng: [35.88, 14.5], name: 'Malta'}, - {latLng: [12.05, -61.75], name: 'Grenada'}, - {latLng: [13.16, -61.23], name: 'Saint Vincent and the Grenadines'}, - {latLng: [13.16, -59.55], name: 'Barbados'}, - {latLng: [17.11, -61.85], name: 'Antigua and Barbuda'}, - {latLng: [-4.61, 55.45], name: 'Seychelles'}, - {latLng: [7.35, 134.46], name: 'Palau'}, - {latLng: [42.5, 1.51], name: 'Andorra'}, - {latLng: [14.01, -60.98], name: 'Saint Lucia'}, - {latLng: [6.91, 158.18], name: 'Federated States of Micronesia'}, - {latLng: [1.3, 103.8], name: 'Singapore'}, - {latLng: [1.46, 173.03], name: 'Kiribati'}, - {latLng: [-21.13, -175.2], name: 'Tonga'}, - {latLng: [15.3, -61.38], name: 'Dominica'}, - {latLng: [-20.2, 57.5], name: 'Mauritius'}, - {latLng: [26.02, 50.55], name: 'Bahrain'}, - {latLng: [0.33, 6.73], name: 'São Tomé and Príncipe'} - ] - }); - - /* SPARKLINE CHARTS - * ---------------- - * Create a inline charts with spark line - */ - - //----------------- - //- SPARKLINE BAR - - //----------------- - $('.sparkbar').each(function () { - var $this = $(this); - $this.sparkline('html', { - type: 'bar', - height: $this.data('height') ? $this.data('height') : '30', - barColor: $this.data('color') - }); - }); - - //----------------- - //- SPARKLINE PIE - - //----------------- - $('.sparkpie').each(function () { - var $this = $(this); - $this.sparkline('html', { - type: 'pie', - height: $this.data('height') ? $this.data('height') : '90', - sliceColors: $this.data('color') - }); - }); - - //------------------ - //- SPARKLINE LINE - - //------------------ - $('.sparkline').each(function () { - var $this = $(this); - $this.sparkline('html', { - type: 'line', - height: $this.data('height') ? $this.data('height') : '90', - width: '100%', - lineColor: $this.data('linecolor'), - fillColor: $this.data('fillcolor'), - spotColor: $this.data('spotcolor') - }); - }); -}); diff --git a/polemarch/static/js/tests/qUnitTest.js b/polemarch/static/js/tests/qUnitTest.js index ef669599..6b137793 100644 --- a/polemarch/static/js/tests/qUnitTest.js +++ b/polemarch/static/js/tests/qUnitTest.js @@ -234,6 +234,11 @@ function saveReport() console.log("saveReport") } +/** + * В этом массиве должны быть qunit тесты для приложения + */ +window.qunitTestsArray = [] + /** * Вставляет Qunit и запускает выполнение тестов. */ @@ -282,7 +287,10 @@ function injectQunit() } }) - qunitAddTests() + for(var i in window.qunitTestsArray) + { + window.qunitTestsArray[i].call() + } syncQUnit.nextTest() }, 500) @@ -321,9 +329,9 @@ syncQUnit.nextTest = function(name, test) /////////////////////////////////////////////// /** - * В этой функции должны быть qunit тесты для приложения + * qunitAddTests_trim */ -function qunitAddTests() +window.qunitTestsArray.push(function() { syncQUnit.addTest('trim', function ( assert ) { var done = assert.async(); @@ -338,21 +346,13 @@ function qunitAddTests() assert.equal(trim(' x y '), 'x y', 'Табы и пробелы внутри строки не трогаем'); render(done); - }); - - qunitAddTests_users() - qunitAddTests_hosts() - qunitAddTests_groups() - qunitAddTests_inventories() - qunitAddTests_projects() - qunitAddTests_templates_task() - qunitAddTests_templates_modules() -} + }); +}) /** * Тестирование users */ -function qunitAddTests_users() +window.qunitTestsArray.push(function() { syncQUnit.addTest('Открытие списка пользователей', function ( assert ) { @@ -584,13 +584,13 @@ function qunitAddTests_users() render(done) }) }); -} +}) /** * Тестирование hosts */ -function qunitAddTests_hosts() +window.qunitTestsArray.push(function() { syncQUnit.addTest('Открытие списка хостов', function ( assert ) { @@ -744,13 +744,13 @@ function qunitAddTests_hosts() render(done) }) }); -} +}) /** * Тестирование groups */ -function qunitAddTests_groups() +window.qunitTestsArray.push(function() { syncQUnit.addTest('Проверка функции validateHostName', function ( assert ) { var done = assert.async(); @@ -1004,13 +1004,13 @@ function qunitAddTests_groups() render(done) }) }); -} +}) /** * Тестирование inventories */ -function qunitAddTests_inventories() +window.qunitTestsArray.push(function() { syncQUnit.addTest('Список инвенториев', function ( assert ) { @@ -1425,12 +1425,12 @@ c2libGVfYmVjb21lPXRydWU=" assert.ok(res, 'Сравнение инвентория 2 распарсенного и оригинального'); render(done) }); -} +}) /** * Тестирование projects */ -function qunitAddTests_projects() +window.qunitTestsArray.push(function() { syncQUnit.addTest('Список проектов', function ( assert ) { @@ -2101,10 +2101,13 @@ function qunitAddTests_projects() render(done) }) }); -} - -function qunitAddTests_templates_task(){ +}) +/** + * Тестирование шаблонов + */ +window.qunitTestsArray.push(function() +{ syncQUnit.addTest('Список шаблонов', function ( assert ) { var done = assert.async(); @@ -2282,10 +2285,13 @@ function qunitAddTests_templates_task(){ render(done) }) }); -} - -function qunitAddTests_templates_modules(){ +}) +/** + * Тестирование шаблонов модулей + */ +window.qunitTestsArray.push(function() +{ syncQUnit.addTest('Список шаблонов', function ( assert ) { var done = assert.async(); @@ -2466,10 +2472,12 @@ function qunitAddTests_templates_modules(){ render(done) }) }); -} - - -function qunitAddTests_history() +}) + +/** + * Тестирование history + */ +window.qunitTestsArray.push(function() { syncQUnit.addTest('Страница history', function ( assert ) { @@ -2486,8 +2494,9 @@ function qunitAddTests_history() }) }); - syncQUnit.addTest('Страница history', function ( assert ) + syncQUnit.addTest('Страница history 2', function ( assert ) { + debugger; var done = assert.async(); if(!pmHistory.model.itemslist.results.length) @@ -2496,7 +2505,7 @@ function qunitAddTests_history() render(done) } - $.when(spajs.open({ menuId:"history/"+pmHistory.model.itemslist.results[0].id+"/"})).done(function() + $.when(spajs.open({ menuId:"history/"+pmHistory.model.itemslist.results[0].id})).done(function() { assert.ok(true, 'Успешно открыта страница history'); render(done) @@ -2507,6 +2516,5 @@ function qunitAddTests_history() }) }); -} +}) -injectQunit() \ No newline at end of file From 95c62f42c8302294803d8806f07f90c1d80859d4 Mon Sep 17 00:00:00 2001 From: Trapenok Victor Date: Fri, 20 Oct 2017 11:58:10 +1000 Subject: [PATCH 005/110] tests for inventory import --- polemarch/static/js/common.js | 73 +++++++++++++++++- polemarch/static/js/pmInventories.js | 103 +++++++++++++++---------- polemarch/static/js/pmItems.js | 11 --- polemarch/static/js/tests/qUnitTest.js | 45 +++++++---- 4 files changed, 162 insertions(+), 70 deletions(-) diff --git a/polemarch/static/js/common.js b/polemarch/static/js/common.js index b8720d1f..49229417 100644 --- a/polemarch/static/js/common.js +++ b/polemarch/static/js/common.js @@ -11,4 +11,75 @@ function loadQUnitTests() injectQunit() } }, 1000) -} \ No newline at end of file +} + + +function addslashes(string) { + return string.replace(/\\/g, '\\\\'). + replace(/\u0008/g, '\\b'). + replace(/\t/g, '\\t'). + replace(/\n/g, '\\n'). + replace(/\f/g, '\\f'). + //replace(/\r/g, '\\r'). + //replace(/\a/g, '\\a'). + replace(/\v/g, '\\v'). + //replace(/\e/g, '\\e'). + replace(/'/g, '\\\''). + replace(/"/g, '\\"'); +} + +function stripslashes (str) { + // discuss at: http://locutus.io/php/stripslashes/ + // original by: Kevin van Zonneveld (http://kvz.io) + // improved by: Ates Goral (http://magnetiq.com) + // improved by: marrtins + // improved by: rezna + // fixed by: Mick@el + // bugfixed by: Onno Marsman (https://twitter.com/onnomarsman) + // bugfixed by: Brett Zamir (http://brett-zamir.me) + // input by: Rick Waldron + // input by: Brant Messenger (http://www.brantmessenger.com/) + // reimplemented by: Brett Zamir (http://brett-zamir.me) + // example 1: stripslashes('Kevin\'s code') + // returns 1: "Kevin's code" + // example 2: stripslashes('Kevin\\\'s code') + // returns 2: "Kevin\'s code" + return (str + '') + .replace(/\\(.?)/g, function (s, n1) { + switch (n1) { + case '\\': + return '\\' + case '0': + return '\u0000' + case 't': + return "\t" + case 'n': + return "\n" + case 'f': + return "\f" + //case 'e': + // return "\e" + case 'v': + return "\v" + //case 'a': + // return "\a" + case 'b': + return "\b" + //case 'r': + // return "\r" + case '': + return '' + default: + return n1 + } + }) +} +/** + * Тестовый тест, чтоб было видно что тесты вообще хоть как то работают. + */ +function trim(s) +{ + if(s) return s.replace(/^ */g, "").replace(/ *$/g, "") + return ''; +} + diff --git a/polemarch/static/js/pmInventories.js b/polemarch/static/js/pmInventories.js index 439a1fd2..141e6b8d 100644 --- a/polemarch/static/js/pmInventories.js +++ b/polemarch/static/js/pmInventories.js @@ -12,7 +12,7 @@ pmInventories.model.className = "pmInventories" pmInventories.parseMonoVarsLine = function(index, line) { var vars = {} - var param = /^([^=]+)=(.*)$/.exec(line) + var param = /^([^=]+)="(.*)"$/.exec(line) if(param) { @@ -20,17 +20,25 @@ pmInventories.parseMonoVarsLine = function(index, line) } else { - throw "Error in line "+index+" invalid varibles string ("+line+")" + param = /^([^=]+)=(.*)$/.exec(line) + if(param) + { + vars[param[1]] = param[2] + } + else + { + throw "Error in line "+index+" invalid varibles string ("+line+")" + } } return vars; } - + /** * Параметры хоста * Строка где может быть несколько параметров ключ=значение через пробел */ pmInventories.parseVarsLine = function(index, line) -{ +{ var vars = {} do{ if(line.length == 0) @@ -38,37 +46,37 @@ pmInventories.parseVarsLine = function(index, line) break; } - var params = /^([^=]+)=["'](.*?)["'] [^=]+=/.exec(line) + var params = /^([^=]+)=["'](.*?)["'] +[^=]+=/.exec(line) if(params) { - params[1] = trim(params[1]) - vars[params[1]] = params[2] + params[1] = trim(params[1]) + vars[params[1]] = stripslashes(params[2]) line = trim(line.slice(params[1].length + params[2].length + 3)) continue; } - params = /^([^=]+)=["'](.*?)["']$/.exec(line) + params = /^([^=]+)=([^ ]*) +[^=]+=/.exec(line) if(params) { - params[1] = trim(params[1]) - vars[params[1]] = params[2] - break; + params[1] = trim(params[1]) + vars[params[1]] = stripslashes(params[2]) + line = trim(line.slice(params[1].length + params[2].length + 1)) + continue; } - params = /^([^=]+)=(.*?) [^=]+=/.exec(line) + params = /^([^=]+)=["'](.*?)["'] *$/.exec(line) if(params) { - params[1] = trim(params[1]) - vars[params[1]] = params[2] - line = trim(line.slice(params[1].length + params[2].length + 1)) - continue; + params[1] = trim(params[1]) + vars[params[1]] = stripslashes(params[2]) + break; } - params = /^([^=]+)=(.*?)$/.exec(line) + params = /^([^=]+)=([^ ]*) *$/.exec(line) if(params) { - params[1] = trim(params[1]) - vars[params[1]] = params[2] + params[1] = trim(params[1]) + vars[params[1]] = stripslashes(params[2]) line = trim(line.slice(params[1].length + params[2].length + 1)) continue; } @@ -223,7 +231,7 @@ pmInventories.parseFromText = function(text) for(var i in lines) { - var line = lines[i] + var line = lines[i].replace(/^ */g, "") if(/^\s*[#;]\s+inventory name: (.*)/ig.test(line)) { @@ -408,28 +416,41 @@ pmInventories.importInventoriesAndOpen = function(inventory) }).promise() } +pmInventories.showGroupVarsModal = function(opt) +{ + return jsonEditor.jsonEditorScrollTo("ansible_ssh_private_key_file", "group"+opt.name) +} + +pmInventories.showHostVarsModal = function(opt) +{ + return jsonEditor.jsonEditorScrollTo("ansible_ssh_private_key_file", "host"+opt.name) +} + +pmInventories.showInventoryVarsModal = function(opt) +{ + return jsonEditor.jsonEditorScrollTo("ansible_ssh_private_key_file", "inventory") +} + pmInventories.importInventory = function(inventory) { - var def2 = new $.Deferred(); - var vars = jsonEditor.jsonEditorGetValues('inventory') - if(vars.ansible_ssh_private_key_file !== undefined && !/-----BEGIN RSA PRIVATE KEY-----/.test(vars.ansible_ssh_private_key_file)) + var def2 = new $.Deferred(); + if(inventory.vars.ansible_ssh_private_key_file !== undefined && !/-----BEGIN RSA PRIVATE KEY-----/.test(inventory.vars.ansible_ssh_private_key_file)) { // - $.notify("Error in field ansible_ssh_private_key_file invalid value", "error"); - jsonEditor.jsonEditorScrollTo("ansible_ssh_private_key_file", "inventory") + $.notify("Error in field ansible_ssh_private_key_file invalid value", "error"); + pmInventories.showInventoryVarsModal(); def2.reject() return def2.promise(); } for(var i in inventory.hosts) { - var val = inventory.hosts[i] - var vars = jsonEditor.jsonEditorGetValues('host'+val.name) - if(vars.ansible_ssh_private_key_file !== undefined && !/-----BEGIN RSA PRIVATE KEY-----/.test(vars.ansible_ssh_private_key_file)) + var val = inventory.hosts[i] + if(val.vars.ansible_ssh_private_key_file !== undefined && !/-----BEGIN RSA PRIVATE KEY-----/.test(val.vars.ansible_ssh_private_key_file)) { // $.notify("Error in field ansible_ssh_private_key_file invalid value", "error"); - jsonEditor.jsonEditorScrollTo("ansible_ssh_private_key_file", "host"+val.name) + pmInventories.showHostVarsModal({group:'all', name:val.name}); def2.reject() return def2.promise(); } @@ -437,26 +458,24 @@ pmInventories.importInventory = function(inventory) for(var i in inventory.groups) { - var val = inventory.groups[i] - var vars = jsonEditor.jsonEditorGetValues('group'+i) - if(vars.ansible_ssh_private_key_file !== undefined && !/-----BEGIN RSA PRIVATE KEY-----/.test(vars.ansible_ssh_private_key_file)) + var val = inventory.groups[i] + if(val.vars.ansible_ssh_private_key_file !== undefined && !/-----BEGIN RSA PRIVATE KEY-----/.test(val.vars.ansible_ssh_private_key_file)) { // $.notify("Error in field ansible_ssh_private_key_file invalid value", "error"); - jsonEditor.jsonEditorScrollTo("ansible_ssh_private_key_file", "group"+i) + pmInventories.showGroupVarsModal({name:i}); def2.reject() return def2.promise(); } for(var j in val.hosts) { - var hval = val.hosts[j] - var vars = jsonEditor.jsonEditorGetValues('host'+hval.name) - if(vars.ansible_ssh_private_key_file !== undefined && !/-----BEGIN RSA PRIVATE KEY-----/.test(vars.ansible_ssh_private_key_file)) + var hval = val.hosts[j] + if(hval.vars.ansible_ssh_private_key_file !== undefined && !/-----BEGIN RSA PRIVATE KEY-----/.test(hval.vars.ansible_ssh_private_key_file)) { // - $.notify("Error in field ansible_ssh_private_key_file invalid value", "error"); - jsonEditor.jsonEditorScrollTo("ansible_ssh_private_key_file", "host"+hval.name) + $.notify("Error in field ansible_ssh_private_key_file invalid value", "error"); + pmInventories.showHostVarsModal({group:i, name:hval.name}); def2.reject() return def2.promise(); } @@ -479,7 +498,7 @@ pmInventories.importInventory = function(inventory) var inventoryObject = { name:inventory.name, - vars:jsonEditor.jsonEditorGetValues('inventory') + vars:inventory.vars } var deleteBulk = [] @@ -502,7 +521,7 @@ pmInventories.importInventory = function(inventory) data:{ name:i, children:val.children, - vars:jsonEditor.jsonEditorGetValues('group'+i) + vars:val.vars } }) @@ -515,7 +534,7 @@ pmInventories.importInventory = function(inventory) data:{ name:hval.name, type:hval.type, - vars:jsonEditor.jsonEditorGetValues('host'+hval.name) + vars:hval.vars } }) } @@ -532,7 +551,7 @@ pmInventories.importInventory = function(inventory) data:{ name:val.name, type:val.type, - vars:jsonEditor.jsonEditorGetValues('host'+val.name) + vars:val.vars } }) } diff --git a/polemarch/static/js/pmItems.js b/polemarch/static/js/pmItems.js index 99ce69b1..5dc55969 100644 --- a/polemarch/static/js/pmItems.js +++ b/polemarch/static/js/pmItems.js @@ -716,14 +716,3 @@ pmItems.exportSelecedToFile = function(){ return this.exportToFile(item_ids) } - - -/** - * Тестовый тест, чтоб было видно что тесты вообще хоть как то работают. - */ -function trim(s) -{ - if(s) return s.replace(/^ */g, "").replace(/ *$/g, "") - return ''; -} - diff --git a/polemarch/static/js/tests/qUnitTest.js b/polemarch/static/js/tests/qUnitTest.js index 6b137793..11077543 100644 --- a/polemarch/static/js/tests/qUnitTest.js +++ b/polemarch/static/js/tests/qUnitTest.js @@ -347,6 +347,24 @@ window.qunitTestsArray.push(function() render(done); }); + + syncQUnit.addTest('trim', function ( assert ) { + var done = assert.async(); + + var stringArr = [ + "abc", + "A \" A", + "A ' \\ \\\\ \t \\ \ g \" ' \' ", + '"', + 'a"b\' g \" \t \ \\ \\\ c', + ' \' \\ " \t \r \b \e \c \d \n' , + ]; + for(var i in stringArr) + { + assert.equal(stripslashes(addslashes(stringArr[i])), stringArr[i], "i:"+stringArr[i]); + } + render(done); + }); }) /** @@ -1214,7 +1232,7 @@ N0PTEwLjIwLjAuOAo=" 124.3.4.[44:55] 124.3.5.[1:250] ansible_host=10.20.0.2 ansible_user=root ansible_ssh_pass=eadgbe ansible_ssh_private_key_file=/root/f.txt 124.3.5.[1:251] ansible_host="10.20.0.2" ansible_user='root' ansible_ssh_pass=eadgbe -124.3.5.[1:252] ansible_host="10.20.0.12" ansible_user='r"o\'ot' ansible_ssh_pass=eadgbe +124.3.5.[1:252] ansible_host="10.20.0.12" ansible_user="r\"o\'ot" ansible_ssh_pass=eadgbe # Global vars [all:vars] @@ -1280,7 +1298,7 @@ os-controller-2.vst.lan ansible_host=10.20.0.8 }) }); - var etalon = {"hosts":[{"name":"1.2.3.[1:255]","type":"RANGE","vars":{}},{"name":"124.3.4.[44:55]","type":"RANGE","vars":{}},{"name":"124.3.5.[1:250]","type":"RANGE","vars":{"ansible_host":"10.20.0.2","ansible_user":"root","ansible_ssh_pass":"eadgbe","ansible_ssh_private_key_file":"/root/f.txt"}},{"name":"124.3.5.[1:251]","type":"RANGE","vars":{"ansible_host":"10.20.0.2","ansible_user":"root","ansible_ssh_pass":"eadgbe"}},{"name":"124.3.5.[1:252]","type":"RANGE","vars":{"ansible_host":"10.20.0.12","ansible_user":"r\"o\\'ot","ansible_ssh_pass":"eadgbe"}}],"groups":{"git":{"vars":{},"groups":["ci","git-servers"],"hosts":[],"children":true,"dataLevel":{"level":2,"parents":["all","cloud","git"]}},"ci":{"vars":{},"groups":[],"hosts":[{"name":"git-ci-1","type":"HOST","vars":{"ansible_host":"172.16.1.13","ansible_ssh_private_key_file":"/root/f.txt"}},{"name":"git-ci-2","type":"HOST","vars":{"ansible_host":"172.16.1.14"}}],"dataLevel":{"level":3,"parents":["all","cloud","git","ci"]}},"git-servers":{"vars":{},"groups":[],"hosts":[{"name":"git.vst.lan","type":"HOST","vars":{}}],"dataLevel":{"level":3,"parents":["all","cloud","git","git-servers"]}},"cloud":{"vars":{},"groups":["git","services","test"],"hosts":[],"children":true,"dataLevel":{"level":1,"parents":["all","cloud"]}},"services":{"vars":{},"groups":[],"hosts":[{"name":"chat.vstconsulting.net","type":"HOST","vars":{"ansible_host":"172.16.1.16"}},{"name":"pipc.vst.lan","type":"HOST","vars":{}},{"name":"redmine.vst.lan","type":"HOST","vars":{}}],"dataLevel":{"level":2,"parents":["all","cloud","services"]}},"test":{"vars":{"ansible_ssh_private_key_file":"/root/f.txt"},"groups":[],"hosts":[{"name":"test.vst.lan","type":"HOST","vars":{"ansible_user":"centos"}},{"name":"test2.vst.lan","type":"HOST","vars":{"ansible_host":"172.16.1.26"}}],"dataLevel":{"level":2,"parents":["all","cloud","test"]}},"openstack":{"vars":{},"groups":[],"hosts":[{"name":"fuel.vst.lan","type":"HOST","vars":{"ansible_host":"10.20.0.2","ansible_user":"root","ansible_ssh_pass":"eadgbe"}},{"name":"os-compute-1.vst.lan","type":"HOST","vars":{"ansible_host":"10.20.0.9"}},{"name":"os-compute-2.vst.lan","type":"HOST","vars":{"ansible_host":"10.20.0.13","ansible_ssh_private_key_file":"/root/f.txt"}},{"name":"os-controller-1.vst.lan","type":"HOST","vars":{"ansible_host":"10.20.0.6"}},{"name":"os-controller-2.vst.lan","type":"HOST","vars":{"ansible_host":"10.20.0.8"}}],"dataLevel":{"level":1,"parents":["all","openstack"]}}},"vars":{"ansible_user":"grey","ansible_ssh_private_key_file":"/root/f.txt","ansible_ssh_extra_args":"-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"},"name":"inventory"} + var etalon = {"hosts":[{"name":"1.2.3.[1:255]","type":"RANGE","vars":{}},{"name":"124.3.4.[44:55]","type":"RANGE","vars":{}},{"name":"124.3.5.[1:250]","type":"RANGE","vars":{"ansible_host":"10.20.0.2","ansible_user":"root","ansible_ssh_pass":"eadgbe","ansible_ssh_private_key_file":"/root/f.txt"}},{"name":"124.3.5.[1:251]","type":"RANGE","vars":{"ansible_host":"10.20.0.2","ansible_user":"root","ansible_ssh_pass":"eadgbe"}},{"name":"124.3.5.[1:252]","type":"RANGE","vars":{"ansible_host":"10.20.0.12","ansible_user":"r\"o\'ot","ansible_ssh_pass":"eadgbe"}}],"groups":{"git":{"vars":{},"groups":["ci","git-servers"],"hosts":[],"children":true,"dataLevel":{"level":2,"parents":["all","cloud","git"]}},"ci":{"vars":{},"groups":[],"hosts":[{"name":"git-ci-1","type":"HOST","vars":{"ansible_host":"172.16.1.13","ansible_ssh_private_key_file":"/root/f.txt"}},{"name":"git-ci-2","type":"HOST","vars":{"ansible_host":"172.16.1.14"}}],"dataLevel":{"level":3,"parents":["all","cloud","git","ci"]}},"git-servers":{"vars":{},"groups":[],"hosts":[{"name":"git.vst.lan","type":"HOST","vars":{}}],"dataLevel":{"level":3,"parents":["all","cloud","git","git-servers"]}},"cloud":{"vars":{},"groups":["git","services","test"],"hosts":[],"children":true,"dataLevel":{"level":1,"parents":["all","cloud"]}},"services":{"vars":{},"groups":[],"hosts":[{"name":"chat.vstconsulting.net","type":"HOST","vars":{"ansible_host":"172.16.1.16"}},{"name":"pipc.vst.lan","type":"HOST","vars":{}},{"name":"redmine.vst.lan","type":"HOST","vars":{}}],"dataLevel":{"level":2,"parents":["all","cloud","services"]}},"test":{"vars":{"ansible_ssh_private_key_file":"/root/f.txt"},"groups":[],"hosts":[{"name":"test.vst.lan","type":"HOST","vars":{"ansible_user":"centos"}},{"name":"test2.vst.lan","type":"HOST","vars":{"ansible_host":"172.16.1.26"}}],"dataLevel":{"level":2,"parents":["all","cloud","test"]}},"openstack":{"vars":{},"groups":[],"hosts":[{"name":"fuel.vst.lan","type":"HOST","vars":{"ansible_host":"10.20.0.2","ansible_user":"root","ansible_ssh_pass":"eadgbe"}},{"name":"os-compute-1.vst.lan","type":"HOST","vars":{"ansible_host":"10.20.0.9"}},{"name":"os-compute-2.vst.lan","type":"HOST","vars":{"ansible_host":"10.20.0.13","ansible_ssh_private_key_file":"/root/f.txt"}},{"name":"os-controller-1.vst.lan","type":"HOST","vars":{"ansible_host":"10.20.0.6"}},{"name":"os-controller-2.vst.lan","type":"HOST","vars":{"ansible_host":"10.20.0.8"}}],"dataLevel":{"level":1,"parents":["all","openstack"]}}},"vars":{"ansible_user":"grey","ansible_ssh_private_key_file":"/root/f.txt","ansible_ssh_extra_args":"-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"},"name":"inventory"} var inventory = undefined; syncQUnit.addTest('Парсинг inventory', function ( assert ) @@ -1293,7 +1311,7 @@ os-controller-2.vst.lan ansible_host=10.20.0.8 inventory:inventory, text:pmInventoriesText } - + var res = deepEqual(etalon, inventory) assert.ok(res, 'Сравнение инвентория распарсенного и оригинального'); render(done) @@ -1326,24 +1344,20 @@ os-controller-2.vst.lan ansible_host=10.20.0.8 syncQUnit.addTest('Импорт валидного inventory', function ( assert ) { - jsonEditor.jsonEditorRmVar('ansible_ssh_private_key_file', 'inventory') + delete inventory.vars.ansible_ssh_private_key_file for(var i in inventory.hosts) - { - var val = inventory.hosts[i] - jsonEditor.jsonEditorRmVar('ansible_ssh_private_key_file', 'host'+val.name) + { + delete inventory.hosts[i].vars.ansible_ssh_private_key_file } for(var i in inventory.groups) { - var val = inventory.groups[i] - jsonEditor.jsonEditorRmVar('ansible_ssh_private_key_file', "group"+i) - - for(var j in val.hosts) + delete inventory.groups[i].vars.ansible_ssh_private_key_file + for(var j in inventory.groups[i].hosts) { - var hval = val.hosts[j] - jsonEditor.jsonEditorRmVar('ansible_ssh_private_key_file', "host"+hval.name) + delete inventory.groups[i].hosts[j].vars.ansible_ssh_private_key_file } } - + var done = assert.async(); $("#inventory_name").val("inventory") $.when(pmInventories.importInventory(inventory)).done(function() @@ -2495,8 +2509,7 @@ window.qunitTestsArray.push(function() }); syncQUnit.addTest('Страница history 2', function ( assert ) - { - debugger; + { var done = assert.async(); if(!pmHistory.model.itemslist.results.length) From aae1d6b33779cc06597e1ff8bd57800d938bb836 Mon Sep 17 00:00:00 2001 From: Trapenok Victor Date: Tue, 24 Oct 2017 15:41:28 +1000 Subject: [PATCH 006/110] search form refactoring --- polemarch/static/js/libs/just-watch.js | 2 +- polemarch/static/js/pmItems.js | 44 ++++++++++++--- polemarch/static/js/polemarch.js | 12 ++--- polemarch/static/templates/pmGroups.html | 35 ++++++------ polemarch/static/templates/pmHistory.html | 54 +++++++++---------- polemarch/static/templates/pmHosts.html | 2 +- polemarch/static/templates/pmInventories.html | 2 +- .../static/templates/pmPeriodicTasks.html | 2 +- polemarch/static/templates/pmProjects.html | 2 +- .../static/templates/pmTasksTemplates.html | 2 +- polemarch/static/templates/pmUsers.html | 2 +- 11 files changed, 95 insertions(+), 64 deletions(-) diff --git a/polemarch/static/js/libs/just-watch.js b/polemarch/static/js/libs/just-watch.js index d93205a4..27ef3b86 100644 --- a/polemarch/static/js/libs/just-watch.js +++ b/polemarch/static/js/libs/just-watch.js @@ -538,7 +538,7 @@ var justReactive = { }); if(Array.isArray(newval.val)) - { + { Object.defineProperty(this[opt.prop], 'splice', { enumerable: false , configurable: true diff --git a/polemarch/static/js/pmItems.js b/polemarch/static/js/pmItems.js index 5dc55969..0a5deeb0 100644 --- a/polemarch/static/js/pmItems.js +++ b/polemarch/static/js/pmItems.js @@ -153,6 +153,13 @@ pmItems.validateRangeName = function(name) } +/** + * Строит страницу со списком объектоа + * @param {type} holder + * @param {type} menuInfo + * @param {type} data + * @returns {$.Deferred} + */ pmItems.showList = function(holder, menuInfo, data) { var thisObj = this; @@ -172,6 +179,10 @@ pmItems.showList = function(holder, menuInfo, data) }) } +/** + * @param {string} query + * @returns {HTML} Шаблон формы поиска + */ pmItems.searchFiled = function(options) { options.className = this.model.className; @@ -179,6 +190,11 @@ pmItems.searchFiled = function(options) return spajs.just.render('searchFiled', {opt:options}); } +/** + * Выполняет переход на страницу с результатами поиска + * @param {string} query + * @returns {$.Deferred} + */ pmItems.search = function(query, options) { if(this.isEmptySearchQuery(query)) @@ -189,6 +205,11 @@ pmItems.search = function(query, options) return spajs.open({ menuId:this.model.name+"/search/"+this.searchObjectToString(trim(query)), reopen:true}); } +/** + * Если поисковый запрос пуст то вернёт true + * @param {type} query + * @returns {Boolean} + */ pmItems.isEmptySearchQuery = function(query) { if(!query || !trim(query)) @@ -199,6 +220,13 @@ pmItems.isEmptySearchQuery = function(query) return false; } +/** + * Строит страницу результатов поиска на основе урла страницы + * @param {type} holder + * @param {type} menuInfo + * @param {type} data + * @returns {$.Deferred} + */ pmItems.showSearchResults = function(holder, menuInfo, data) { var thisObj = this; @@ -410,15 +438,19 @@ pmItems.sendSearchQuery = function(query, limit, offset) { if(!limit) { - limit = 999; + limit = 999; } if(!offset) { - offset = 0; + offset = 0; } var q = []; + + q.push("limit="+encodeURIComponent(limit)) + q.push("offset="+encodeURIComponent(offset)) + for(var i in query) { if(Array.isArray(query[i])) @@ -432,13 +464,13 @@ pmItems.sendSearchQuery = function(query, limit, offset) } q.push(encodeURIComponent(i)+"="+encodeURIComponent(query[i])) } + var thisObj = this; return spajs.ajax.Call({ - url: "/api/v1/"+this.model.name+"/filter/", - type: "POST", - contentType:'application/json', - data: JSON.stringify({filter:query}), // "limit="+encodeURIComponent(limit)+"&offset="+encodeURIComponent(offset), + url: "/api/v1/"+this.model.name+"/?"+q.join("&"), + type: "GET", + contentType:'application/json', success: function(data) { //console.log("update Items", data) diff --git a/polemarch/static/js/polemarch.js b/polemarch/static/js/polemarch.js index 44d831b0..890f4c0f 100644 --- a/polemarch/static/js/polemarch.js +++ b/polemarch/static/js/polemarch.js @@ -123,7 +123,7 @@ polemarch.start = function(options) // users spajs.addMenu({ id:"users", - urlregexp:[/^users$/, /^user$/, /^users\/page\/([0-9]+)$/], + urlregexp:[/^users$/, /^user$/, /^users\/search\/?$/, /^users\/page\/([0-9]+)$/], onOpen:function(holder, menuInfo, data){return pmUsers.showList(holder, menuInfo, data);} }) @@ -149,7 +149,7 @@ polemarch.start = function(options) // hosts spajs.addMenu({ id:"hosts", - urlregexp:[/^hosts$/, /^host$/, /^hosts\/page\/([0-9]+)$/], + urlregexp:[/^hosts$/, /^host$/, /^hosts\/search\/?$/, /^hosts\/page\/([0-9]+)$/], onOpen:function(holder, menuInfo, data){return pmHosts.showList(holder, menuInfo, data);} }) @@ -175,7 +175,7 @@ polemarch.start = function(options) // groups spajs.addMenu({ id:"groups", - urlregexp:[/^groups$/, /^group$/, /^groups\/page\/([0-9]+)$/], + urlregexp:[/^groups$/, /^group$/, /^groups\/search\/?$/, /^groups\/page\/([0-9]+)$/], onOpen:function(holder, menuInfo, data){return pmGroups.showList(holder, menuInfo, data);} }) @@ -200,7 +200,7 @@ polemarch.start = function(options) // inventories spajs.addMenu({ id:"inventories", - urlregexp:[/^inventories$/, /^inventory$/, /^inventories\/page\/([0-9]+)$/], + urlregexp:[/^inventories$/, /^inventory$/, /^inventories\/search\/?$/, /^inventories\/page\/([0-9]+)$/], onOpen:function(holder, menuInfo, data){return pmInventories.showList(holder, menuInfo, data);} }) @@ -238,7 +238,7 @@ polemarch.start = function(options) // projects spajs.addMenu({ id:"projects", - urlregexp:[/^projects$/, /^project$/, /^projects\/page\/([0-9]+)$/], + urlregexp:[/^projects$/, /^projects\/search\/?$/, /^project$/, /^projects\/page\/([0-9]+)$/], onOpen:function(holder, menuInfo, data){return pmProjects.showUpdatedList(holder, menuInfo, data);}, onClose:function(){return pmProjects.stopUpdates();}, }) @@ -301,7 +301,7 @@ polemarch.start = function(options) // history spajs.addMenu({ id:"history", - urlregexp:[/^history$/, /^history\/page\/([0-9]+)$/], + urlregexp:[/^history$/, /^history\/search\/?$/, /^history\/page\/([0-9]+)$/], onOpen:function(holder, menuInfo, data){return pmHistory.showUpdatedList(holder, menuInfo, data);}, onClose:function(){return pmHistory.stopUpdates();}, }) diff --git a/polemarch/static/templates/pmGroups.html b/polemarch/static/templates/pmGroups.html index 470c67dc..4a2c03e0 100644 --- a/polemarch/static/templates/pmGroups.html +++ b/polemarch/static/templates/pmGroups.html @@ -20,8 +20,8 @@

      - Groups - <%= pmGroups.searchFiled({query:query}) %> +
      Groups
      + <%= pmGroups.searchFiled({query:query}) %> <% if(pmGroups.getTotalPages(pmGroups.model.itemslist)){ %>

    • Delete all selected elements
    - + <% if(!query){ %>
    -
    From 764a4f20f81d0bacf5980d9315884022c9a31d41 Mon Sep 17 00:00:00 2001 From: Trapenok Victor Date: Thu, 30 Nov 2017 14:11:53 +1000 Subject: [PATCH 104/110] fix bugs before release --- polemarch/static/templates/pmHistory.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polemarch/static/templates/pmHistory.html b/polemarch/static/templates/pmHistory.html index d813a781..546403d7 100644 --- a/polemarch/static/templates/pmHistory.html +++ b/polemarch/static/templates/pmHistory.html @@ -50,7 +50,7 @@

    <%- val.id + " - " + val.mode %> + onclick="return spajs.openURL(this.href);" ><%- val.mode %> <% if(pmProjects.model.items[val.project]){ %> From a755ff2325da8579ae1613b159e54e0cd6f2751c Mon Sep 17 00:00:00 2001 From: Trapenok Victor Date: Thu, 30 Nov 2017 17:47:13 +1000 Subject: [PATCH 105/110] fix bugs before release --- polemarch/static/templates/pmPeriodicTasks.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/polemarch/static/templates/pmPeriodicTasks.html b/polemarch/static/templates/pmPeriodicTasks.html index 013b1609..1bf13c7c 100644 --- a/polemarch/static/templates/pmPeriodicTasks.html +++ b/polemarch/static/templates/pmPeriodicTasks.html @@ -396,14 +396,14 @@

    sec

  • - - -
    - - <%= crontabEditor.editor({string:''}) %> -
    + +
    + + <%= crontabEditor.editor({string:''}) %> +
    +
    From 2f61c90d9c3f1da6793216ee53dc2492f6767374 Mon Sep 17 00:00:00 2001 From: cepreu Date: Thu, 30 Nov 2017 17:54:58 +1000 Subject: [PATCH 106/110] fixed issues with run with inventories files from project (issue #36) --- .../static/templates/pmPeriodicTasks.html | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/polemarch/static/templates/pmPeriodicTasks.html b/polemarch/static/templates/pmPeriodicTasks.html index 1bf13c7c..b6f08ab2 100644 --- a/polemarch/static/templates/pmPeriodicTasks.html +++ b/polemarch/static/templates/pmPeriodicTasks.html @@ -234,15 +234,16 @@

    -
    - - <% if(pmPeriodicTasks.model.items[item_id].type == 'CRONTAB'){ %> - <%= crontabEditor.editor({string:pmPeriodicTasks.model.items[item_id].schedule}) %> - <% }else{ %> - <%= crontabEditor.editor({string:''}) %> - <% } %> -
    -
    +
    + + <% if(pmPeriodicTasks.model.items[item_id].type == 'CRONTAB'){ %> + <%= crontabEditor.editor({string:pmPeriodicTasks.model.items[item_id].schedule}) %> + <% }else{ %> + <%= crontabEditor.editor({string:''}) %> + <% } %> +
    +
    + <% }else{ %> <% } %> From 0ca18b7d5284a107befb2f395018afed3fe11a97 Mon Sep 17 00:00:00 2001 From: Trapenok Victor Date: Thu, 30 Nov 2017 18:05:15 +1000 Subject: [PATCH 107/110] fix bugs before release --- polemarch/static/templates/pmHistory.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/polemarch/static/templates/pmHistory.html b/polemarch/static/templates/pmHistory.html index 546403d7..be444b53 100644 --- a/polemarch/static/templates/pmHistory.html +++ b/polemarch/static/templates/pmHistory.html @@ -73,7 +73,7 @@

    <%= pmPeriodicTasks.model.items[val.initiator].justText('name') %> <% }else{ %> - <%- pmHistory.model.items[item_id].initiator_type %> + <%- val.initiator_type %> <% } %> @@ -202,7 +202,7 @@

    <%= pmPeriodicTasks.model.items[val.initiator].justText('name') %> <% }else{ %> - <%- pmHistory.model.items[item_id].initiator_type %> + <%- val.initiator_type %> <% } %> @@ -335,7 +335,7 @@

    <%= pmPeriodicTasks.model.items[val.initiator].justText('name') %> <% }else{ %> - <%- pmHistory.model.items[item_id].initiator_type %> + <%- val.initiator_type %> <% } %> From cf07cc3dcb89607107f8d45816242f9dadcf5594 Mon Sep 17 00:00:00 2001 From: Trapenok Victor Date: Fri, 1 Dec 2017 13:45:40 +1000 Subject: [PATCH 108/110] fix bugs before release --- polemarch/static/js/pmItems.js | 4 +- polemarch/static/js/pmUsers.js | 88 ++++++++++++++++++++++++++-------- 2 files changed, 69 insertions(+), 23 deletions(-) diff --git a/polemarch/static/js/pmItems.js b/polemarch/static/js/pmItems.js index 076fa99e..deb4e742 100644 --- a/polemarch/static/js/pmItems.js +++ b/polemarch/static/js/pmItems.js @@ -836,7 +836,7 @@ pmItems.addItem = function(parent_type, parent_item, opt) if(this.model.page_new.onBeforeSave) { data = this.model.page_new.onBeforeSave.apply(this, [data, opt]); - if(data === undefined) + if(data == undefined || data == false) { def.reject() return def.promise(); @@ -899,7 +899,7 @@ pmItems.updateItem = function(item_id, opt) if(this.model.page_item.onBeforeSave) { data = this.model.page_item.onBeforeSave.apply(this, [data, item_id, opt]); - if(data === undefined) + if(data == undefined || data == false) { def.reject() return def.promise(); diff --git a/polemarch/static/js/pmUsers.js b/polemarch/static/js/pmUsers.js index c2d1eaec..3b60f42b 100644 --- a/polemarch/static/js/pmUsers.js +++ b/polemarch/static/js/pmUsers.js @@ -32,7 +32,12 @@ pmUsers.model.page_list = { ] } -pmUsers.fileds = [ +// pmUsers.fileds = + +pmUsers.model.page_new = { + title: "New user", + short_title: "New user", + fileds:[ [ { filed: new filedsLib.filed.text(), @@ -63,10 +68,6 @@ pmUsers.fileds = [ name:'email', placeholder:'Enter user email', help:'', - validator:function(value){ - return filedsLib.validator.notEmpty(value, 'Email') - }, - fast_validator:function(value){ return value != '' && value} }, { filed: new filedsLib.filed.text(), @@ -74,10 +75,6 @@ pmUsers.fileds = [ name:'first_name', placeholder:'Enter user first name', help:'', - validator:function(value){ - return filedsLib.validator.notEmpty(value, 'First name') - }, - fast_validator:function(value){ return value != '' && value} }, ],[ { @@ -86,10 +83,6 @@ pmUsers.fileds = [ name:'last_name', placeholder:'Enter user last name', help:'', - validator:function(value){ - return filedsLib.validator.notEmpty(value, 'Last name') - }, - fast_validator:function(value){ return value != '' && value} }, { filed: new filedsLib.filed.boolean(), @@ -97,12 +90,7 @@ pmUsers.fileds = [ name:'is_active', } ] - ] - -pmUsers.model.page_new = { - title: "New user", - short_title: "New user", - fileds:pmUsers.fileds, + ], onCreate:function(result) { var def = new $.Deferred(); @@ -143,11 +131,69 @@ pmUsers.model.page_item = { short_title: function(item_id){ return "User "+pmUsers.model.items[item_id].justText('username', function(v){return v.slice(0, 20)}) }, - fileds:pmUsers.fileds, + fileds:[ + [ + { + filed: new filedsLib.filed.text(), + title:'User name', + name:'username', + placeholder:'Enter user name', + help:'', + validator:function(value){ + return filedsLib.validator.notEmpty(value, 'Name') + }, + fast_validator:function(value){ return value != '' && value} + }, + { + filed: new filedsLib.filed.password(), + title:'Password', + name:'password', + placeholder:'Enter user password', + help:'', + }, + ],[ + { + filed: new filedsLib.filed.text(), + title:'Email', + name:'email', + placeholder:'Enter user email', + help:'', + }, + { + filed: new filedsLib.filed.text(), + title:'First name', + name:'first_name', + placeholder:'Enter user first name', + help:'', + }, + ],[ + { + filed: new filedsLib.filed.text(), + title:'Last name', + name:'last_name', + placeholder:'Enter user last name', + help:'', + }, + { + filed: new filedsLib.filed.boolean(), + title:'Is active', + name:'is_active', + } + ] + ], onUpdate:function(result) { return true; - } + }, + onBeforeSave:function(data, item_id) + { + if(!data.password) + { + delete data.password + } + + return data; + }, } From 38130b7fb01704b27a0bcd7431187770c5f23d95 Mon Sep 17 00:00:00 2001 From: Trapenok Victor Date: Fri, 1 Dec 2017 13:51:03 +1000 Subject: [PATCH 109/110] fix bugs before release --- polemarch/static/templates/pmHistory.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/polemarch/static/templates/pmHistory.html b/polemarch/static/templates/pmHistory.html index be444b53..cdf2c56d 100644 --- a/polemarch/static/templates/pmHistory.html +++ b/polemarch/static/templates/pmHistory.html @@ -73,7 +73,7 @@

    <%= pmPeriodicTasks.model.items[val.initiator].justText('name') %> <% }else{ %> - <%- val.initiator_type %> + scheduler <% } %> @@ -202,7 +202,7 @@

    <%= pmPeriodicTasks.model.items[val.initiator].justText('name') %> <% }else{ %> - <%- val.initiator_type %> + scheduler <% } %> @@ -335,7 +335,7 @@

    <%= pmPeriodicTasks.model.items[val.initiator].justText('name') %> <% }else{ %> - <%- val.initiator_type %> + scheduler <% } %> @@ -480,7 +480,7 @@

    <%= pmPeriodicTasks.model.items[pmHistory.model.items[item_id].initiator].justText('name') %> <% }else{ %> - From <%- pmHistory.model.items[item_id].initiator_type %> + From scheduler <% } %>
    @@ -633,7 +633,7 @@

    <%= pmPeriodicTasks.model.items[pmHistory.model.items[item_id].initiator].justText('name') %> <% }else{ %> - From <%- pmHistory.model.items[item_id].initiator_type %> + From scheduler <% } %>
    From b1fffc33d2c705ca853d3da1cfda85137894bce1 Mon Sep 17 00:00:00 2001 From: cepreu Date: Fri, 1 Dec 2017 15:30:35 +1000 Subject: [PATCH 110/110] fixed task canceling with files from project (issue cloud/polemarchplus#52) --- polemarch/main/models/tasks.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/polemarch/main/models/tasks.py b/polemarch/main/models/tasks.py index f390db03..2b6b33fb 100644 --- a/polemarch/main/models/tasks.py +++ b/polemarch/main/models/tasks.py @@ -370,6 +370,8 @@ def write_line(self, value, number): # nocv ) def editable_by(self, user): + if self.inventory is None: + return self.project.editable_by(user) return self.inventory.editable_by(user) def viewable_by(self, user):