mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-20 11:52:37 +09:00
feature #4184: Add label filtering and dropdown
This commit is contained in:
1 parent
40a3a6c447
commit
b8a45cfba2
7 files changed
+336
-15
No files matched your search
@@ -454,13 +454,13 @@ define(function(require) {
|
||||
|
||||
var _setupTabs = function() {
|
||||
var topTabs = $(".left-content ul li.topTab");
|
||||
var subTabs = $(".left-content ul li.subTab");
|
||||
var subTabs = $(".left-content ul li.subTab > a");
|
||||
|
||||
subTabs.on("click", function() {
|
||||
if ($(this).hasClass('topTab')) {
|
||||
if ($(this).closest('li').hasClass('topTab')) {
|
||||
return false;
|
||||
} else {
|
||||
var tabName = $(this).attr('id').substring(3);
|
||||
var tabName = $(this).closest('li').attr('id').substring(3);
|
||||
_showTab(tabName);
|
||||
return false;
|
||||
}
|
||||
@@ -527,6 +527,7 @@ define(function(require) {
|
||||
//clean selected menu
|
||||
$("#navigation li").removeClass("navigation-active-li");
|
||||
$("#navigation li#li_" + tabName).addClass("navigation-active-li");
|
||||
$('.tree', '#navigation').remove();
|
||||
|
||||
var tab = $('#' + tabName);
|
||||
//show tab
|
||||
@@ -534,6 +535,9 @@ define(function(require) {
|
||||
|
||||
var dataTable = SunstoneCfg['tabs'][tabName]['dataTable'];
|
||||
if (dataTable) {
|
||||
if (dataTable.clearLabelsFilter) {
|
||||
dataTable.clearLabelsFilter();
|
||||
}
|
||||
dataTable.recountCheckboxes();
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
</span>
|
||||
|
||||
<span class="right" style="margin-left: 20px">
|
||||
<button href='#' data-dropdown='{{customId}}LabelsDropdown' class='only-right-info only-right-list top_button small secondary button dropdown radius'>
|
||||
<i class='fa fa-tags'/></button>
|
||||
<ul id='{{customId}}LabelsDropdown' class='labels-dropdown only-right-info only-right-list f-dropdown' data-dropdown-content></ul>
|
||||
|
||||
<button href='#' data-dropdown='{{customId}}user_buttons' class='only-right-info only-right-list top_button small secondary button dropdown radius'>
|
||||
<i class='fa fa-user'/></button>
|
||||
<ul id='{{customId}}user_buttons' class='only-right-info only-right-list f-dropdown' data-dropdown-content></ul>
|
||||
|
||||
@@ -23,6 +23,8 @@ define(function(require) {
|
||||
var SunstoneConfig = require('sunstone-config');
|
||||
var Locale = require('utils/locale');
|
||||
var Humanize = require('utils/humanize');
|
||||
var LabelsUtils = require('utils/labels/utils');
|
||||
var Tree = require('utils/labels/tree');
|
||||
|
||||
/*
|
||||
CONSTANTS
|
||||
@@ -60,7 +62,8 @@ define(function(require) {
|
||||
Locale.tr("Owner") ,
|
||||
Locale.tr("Group"),
|
||||
Locale.tr("Name"),
|
||||
Locale.tr("Registration time")
|
||||
Locale.tr("Registration time"),
|
||||
Locale.tr("Labels")
|
||||
];
|
||||
|
||||
this.selectOptions = {
|
||||
@@ -72,12 +75,17 @@ define(function(require) {
|
||||
"you_selected_multiple": Locale.tr("You selected the following Templates:")
|
||||
};
|
||||
|
||||
this.labels = [];
|
||||
|
||||
TabDataTable.call(this);
|
||||
};
|
||||
|
||||
Table.prototype = Object.create(TabDataTable.prototype);
|
||||
Table.prototype.constructor = Table;
|
||||
Table.prototype.elementArray = _elementArray;
|
||||
Table.prototype.preUpdateView = _preUpdateView;
|
||||
Table.prototype.postUpdateView = _postUpdateView;
|
||||
Table.prototype.clearLabelsFilter = _clearLabelsFilter;
|
||||
|
||||
return Table;
|
||||
|
||||
@@ -88,6 +96,11 @@ define(function(require) {
|
||||
function _elementArray(element_json) {
|
||||
var element = element_json[XML_ROOT];
|
||||
|
||||
var labelsStr = LabelsUtils.labelsStr(element);
|
||||
if (labelsStr) {
|
||||
this.labels.push(labelsStr);
|
||||
}
|
||||
|
||||
return [
|
||||
'<input class="check_item" type="checkbox" id="' + RESOURCE.toLowerCase() + '_' +
|
||||
element.ID + '" name="selected_items" value="' +
|
||||
@@ -96,7 +109,77 @@ define(function(require) {
|
||||
element.UNAME,
|
||||
element.GNAME,
|
||||
element.NAME,
|
||||
Humanize.prettyTime(element.REGTIME)
|
||||
Humanize.prettyTime(element.REGTIME),
|
||||
(labelsStr||'')
|
||||
];
|
||||
}
|
||||
|
||||
function _preUpdateView() {
|
||||
this.labels = [];
|
||||
}
|
||||
|
||||
function _postUpdateView() {
|
||||
var that = this;
|
||||
var labels = LabelsUtils.deserializeLabels(this.labels.join(','));
|
||||
/*var labelsDropdown = $('#' + TAB_NAME + 'LabelsDropdown');
|
||||
labelsDropdown.html(Tree.html(LabelsUtils.makeTree(labels)));
|
||||
labelsDropdown.on('change', '.labelCheckbox', function() {
|
||||
var regExp = [];
|
||||
var label;
|
||||
$('.labelCheckbox:checked', labelsDropdown).each(function() {
|
||||
label = $(this).closest('span').attr('one-label-full-name');
|
||||
regExp.push('^' + label + '$');
|
||||
regExp.push(',' + label + '$');
|
||||
regExp.push('^' + label + ',');
|
||||
regExp.push(',' + label + ',');
|
||||
});
|
||||
|
||||
that.dataTable.fnFilter(regExp.join('|'), 6, true, false);
|
||||
});*/
|
||||
$('.labels-tree', '#li_' + TAB_NAME).remove();
|
||||
$('#li_' + TAB_NAME).append(Tree.html(LabelsUtils.makeTree(labels), true));
|
||||
Tree.setup($('.labels-tree', '#li_' + TAB_NAME));
|
||||
|
||||
$('#' + TAB_NAME + 'LabelsDropdown').html(
|
||||
'<div>' +
|
||||
'<h6>' + Locale.tr('Edit Labels') + '</h6>' +
|
||||
Tree.html(LabelsUtils.makeTree(labels), false) +
|
||||
'<div class="input-container">' +
|
||||
'<input type="text" placeholder="' + Locale.tr("Add Label") + '"/>' +
|
||||
'</div>' +
|
||||
'</div>');
|
||||
|
||||
$('#li_' + TAB_NAME).off('click', '.one-label');
|
||||
$('#li_' + TAB_NAME).on('click', '.one-label', function() {
|
||||
var regExp = [];
|
||||
var label = $(this).attr('one-label-full-name');
|
||||
regExp.push('^' + label + '$');
|
||||
regExp.push(',' + label + '$');
|
||||
regExp.push('^' + label + ',');
|
||||
regExp.push(',' + label + ',');
|
||||
that.dataTable.fnFilter(regExp.join('|'), 6, true, false);
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
/*$('#li_' + TAB_NAME).off('change', '.labelCheckbox');
|
||||
$('#li_' + TAB_NAME).on('change', '.labelCheckbox', function() {
|
||||
var regExp = [];
|
||||
var label;
|
||||
$('.labelCheckbox:checked', '#li_' + TAB_NAME).each(function() {
|
||||
label = $(this).closest('span').attr('one-label-full-name');
|
||||
regExp.push('^' + label + '$');
|
||||
regExp.push(',' + label + '$');
|
||||
regExp.push('^' + label + ',');
|
||||
regExp.push(',' + label + ',');
|
||||
});
|
||||
|
||||
that.dataTable.fnFilter(regExp.join('|'), 6, true, false);
|
||||
return false;
|
||||
});*/
|
||||
}
|
||||
|
||||
function _clearLabelsFilter() {
|
||||
this.dataTable.fnFilter('', 6, true, false);
|
||||
}
|
||||
});
|
||||
@@ -17,7 +17,7 @@
|
||||
define(function(require) {
|
||||
/* DEPENDENCIES */
|
||||
|
||||
var Tree = require('utils/tree');
|
||||
var Tree = require('./tree');
|
||||
var TemplateUtils = require('utils/template-utils');
|
||||
var LabelsUtils = require('./utils');
|
||||
var TableTemplate = require('hbs!./labels-table/table');
|
||||
@@ -38,7 +38,7 @@ define(function(require) {
|
||||
this.element = opts.element;
|
||||
this.resource = opts.resource;
|
||||
this.xmlRoot = opts.xmlRoot;
|
||||
this.labels = LabelsUtils.deserializeLabels(this.element);
|
||||
this.labels = LabelsUtils.deserializeLabels(LabelsUtils.labelsStr(this.element));
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2015, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
define(function(require) {
|
||||
var Locale = require('utils/locale');
|
||||
|
||||
/*
|
||||
CONSTRUCTOR
|
||||
*/
|
||||
|
||||
return {
|
||||
'html': _html,
|
||||
'setup': _setup
|
||||
};
|
||||
|
||||
/*
|
||||
FUNCTION DEFINITIONS
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a <ul> html tree
|
||||
* @param {object} tree Recursive structure of elements with attributes
|
||||
* htmlStr: html to be inserted in this line,
|
||||
* subTree: array of tree elements. Must exist, can be empty
|
||||
* @return {string} html string
|
||||
*/
|
||||
function _html(tree, collapsed){
|
||||
var html;
|
||||
|
||||
if (tree.htmlStr && tree.htmlStr != ""){
|
||||
html = '<ul class="labels-tree">'+_innerHtml(tree, collapsed)+'</ul>';
|
||||
} else {
|
||||
html = '<ul class="labels-tree">';
|
||||
$.each(tree.subTree, function(){
|
||||
html += _innerHtml(this, collapsed);
|
||||
});
|
||||
html += '</ul>';
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
function _innerHtml(tree, collapsed){
|
||||
var html = '<li>';
|
||||
|
||||
if (collapsed) {
|
||||
if (tree.subTree.length > 0) {
|
||||
html += '<i class="fa fa-fw fa-angle-right"></i> ';
|
||||
} else {
|
||||
html += '<i class="fa fa-fw fa-tag"></i> ';
|
||||
}
|
||||
|
||||
html += tree.htmlStr;
|
||||
html += '<ul class="hidden">';
|
||||
} else {
|
||||
if (tree.subTree.length > 0) {
|
||||
html += '<i class="fa fa-fw fa-angle-down"></i> ';
|
||||
} else {
|
||||
html += '<i class="fa fa-fw fa-tag"></i> ';
|
||||
}
|
||||
|
||||
html += tree.htmlStr;
|
||||
html += '<i class="fa fa-fw fa-square-o"></i> ';
|
||||
html += '<ul>';
|
||||
}
|
||||
|
||||
$.each(tree.subTree, function(){
|
||||
html += _innerHtml(this, collapsed);
|
||||
});
|
||||
html += '</ul></li>';
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
function _setup(context){
|
||||
context.on('click', '.fa-angle-right', function() {
|
||||
$('ul:first', $(this).parent('li')).show();
|
||||
$(this).removeClass('fa-angle-right');
|
||||
$(this).addClass('fa-angle-down');
|
||||
});
|
||||
|
||||
context.on('click', '.fa-angle-down', function() {
|
||||
$('ul:first', $(this).parent('li')).hide();
|
||||
$(this).removeClass('fa-angle-down');
|
||||
$(this).addClass('fa-angle-right');
|
||||
});
|
||||
|
||||
context.on('click', '.one-label', function() {
|
||||
$('.one-label', context).removeClass('active');
|
||||
$(this).addClass('active');
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -17,7 +17,7 @@
|
||||
define(function(require) {
|
||||
/* DEPENDENCIES */
|
||||
|
||||
var Tree = require('utils/tree');
|
||||
var Tree = require('./tree');
|
||||
|
||||
var TEMPLATE_ATTR = 'TEMPLATE';
|
||||
var LABELS_ATTR = 'LABELS';
|
||||
@@ -25,20 +25,23 @@ define(function(require) {
|
||||
return {
|
||||
'TEMPLATE_ATTR': TEMPLATE_ATTR,
|
||||
'LABELS_ATTR': LABELS_ATTR,
|
||||
'labelsStr': _labelsStr,
|
||||
'deserializeLabels': _deserializeLabels,
|
||||
'makeTree': _makeTree
|
||||
};
|
||||
|
||||
/* FUNCTION DEFINITIONS */
|
||||
|
||||
function _labelsStr(element) {
|
||||
return element[TEMPLATE_ATTR][LABELS_ATTR];
|
||||
}
|
||||
|
||||
function _deserializeLabels(element) {
|
||||
var labels = element[TEMPLATE_ATTR][LABELS_ATTR];
|
||||
function _deserializeLabels(labelsStr) {
|
||||
var indexedLabels = {};
|
||||
|
||||
if (labels) {
|
||||
if (labelsStr) {
|
||||
var parent;
|
||||
$.each(labels.split(','), function() {
|
||||
$.each(labelsStr.split(','), function() {
|
||||
parent = indexedLabels;
|
||||
$.each(this.split('/'), function() {
|
||||
if (parent[this] == undefined) {
|
||||
@@ -68,9 +71,10 @@ define(function(require) {
|
||||
function _makeSubTree(parentName, folderName, childs) {
|
||||
var fullName = parentName + folderName;
|
||||
var htmlStr =
|
||||
'<span class="label secondary one-label" one-label-full-name="' + fullName + '">' +
|
||||
'<span class="secondary one-label" one-label-full-name="' + fullName + '">' +
|
||||
//'<input type="checkbox" class="labelCheckbox"/> ' +
|
||||
folderName +
|
||||
' <i class="fa fa-times-circle remove-tab"></i>' +
|
||||
//' <i class="fa fa-times-circle remove-tab"></i>' +
|
||||
'</span>';
|
||||
|
||||
var tree = {
|
||||
|
||||
@@ -240,6 +240,7 @@ input.search {
|
||||
color: #222 !important;
|
||||
}
|
||||
|
||||
background: rgba(0,0,0,0.025);
|
||||
border-left: 2px solid #008cba !important;
|
||||
}
|
||||
|
||||
@@ -1325,4 +1326,123 @@ hr {
|
||||
|
||||
.custom_tags td {
|
||||
vertical-align: top;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.labels-tree input[type="checkbox"] {
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.labels-tree {
|
||||
font: inherit;
|
||||
list-style-type: none;
|
||||
padding-bottom: 1em;
|
||||
padding-right: 1em;
|
||||
margin-left: 0;
|
||||
margin-bottom: 0;
|
||||
|
||||
.fa-angle-down, .fa-angle-right {
|
||||
padding: 3px;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background: #bfbfbf;
|
||||
}
|
||||
}
|
||||
|
||||
.fa-tag {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.one-label {
|
||||
cursor: pointer;
|
||||
|
||||
&:hover, &.active {
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.labels-tree ul{
|
||||
font: inherit;
|
||||
list-style-type: none;
|
||||
margin-left: 1em;
|
||||
padding: 0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.labels-tree li{
|
||||
margin: 0;
|
||||
padding: 0 0 0 1em;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.labels-tree li:before, .labels-tree li:after{
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
/* horizontal line on inner list items */
|
||||
.labels-tree li:before{
|
||||
//border-top: 1px solid #999;
|
||||
top: 0.5em;
|
||||
width: 10px;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
/* vertical line on list items */
|
||||
.labels-tree li:after{
|
||||
//border-left: 1px solid #999;
|
||||
height: 100%;
|
||||
width: 0px;
|
||||
top: -0.5em;
|
||||
}
|
||||
|
||||
/* lower line on list items from the first level because they don't have parents */
|
||||
/*.labels-tree > li::after{
|
||||
top: 0.5em;
|
||||
}*/
|
||||
|
||||
/* hide line from the last of the first level list items */
|
||||
/*.labels-tree > li:last-child::after{
|
||||
display: none;
|
||||
}*/
|
||||
|
||||
.labels-tree li:last-child:after{
|
||||
height:1em;
|
||||
}
|
||||
|
||||
.labels-dropdown {
|
||||
margin: 0px;
|
||||
|
||||
h6 {
|
||||
margin: 0.5em 1em;
|
||||
border-bottom: 1px solid #efefef;
|
||||
}
|
||||
|
||||
.input-container {
|
||||
margin: 0 1em;
|
||||
}
|
||||
|
||||
li {
|
||||
cursor: auto;
|
||||
|
||||
&:hover {
|
||||
background: none;
|
||||
}
|
||||
}
|
||||
|
||||
.fa-check-square-o,
|
||||
.fa-square-o,
|
||||
.fa-minus-square-o {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
padding: 2px;
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
background: #bfbfbf;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user