From f510cba81b8f849c9f3bb89802e1629695248bd1 Mon Sep 17 00:00:00 2001 From: "Heekyoung, Oh" Date: Mon, 27 Mar 2017 17:10:06 +0900 Subject: [PATCH] [TIC-Web] Update The Button For The 'Cancel.' - Cancel Button. it depends on a user group. - only admin and master can click this. - and be activated Change-Id: I2c45818becc7af8c95f064f9851f687da44d7dda Signed-off-by: Heekyoung, Oh --- controller/dbquery.js | 9 ++- controller/mic.js | 7 ++- public/src/css/style.css | 12 ++-- public/src/js/model/JobModel.js | 12 ++++ public/src/js/page/job.js | 111 +++++++++++++++++++++++------------ public/src/js/widget/JobTableItem.js | 20 ++++++- 6 files changed, 121 insertions(+), 50 deletions(-) diff --git a/controller/dbquery.js b/controller/dbquery.js index 4349372..8ca54b1 100644 --- a/controller/dbquery.js +++ b/controller/dbquery.js @@ -22,6 +22,9 @@ var mariaSqlClient; var NO_DATA = 0; +var MAX_JOB_PER_PAGE = 10; +var MAX_IMAGE_PER_PAGE = 4; + /** * mariadb */ @@ -81,7 +84,7 @@ mariadb.queries = { 'where tic_job.job_image_id = tic_image.image_id ', 'and tic_job.job_deleted = false ', 'order by tic_job.job_id desc ', - 'limit <%= startNum %> , 10;' + 'limit <%= startNum %> , 4;' ], 'getImagesTotalCount': [ 'select count(image_id) as total_count ', @@ -244,7 +247,7 @@ mariadb.getJobsAllList = function getJobsAllList(req, res) { // strNum reqParam = req.body; pageNum = reqParam.pageNum; - startNum = (pageNum - 1) * 10; + startNum = (pageNum - 1) * MAX_JOB_PER_PAGE; queryString = _.template(_.join(this.queries['getJobsAllList'], ''))({ startNum: startNum @@ -274,7 +277,7 @@ mariadb.getImagesAllList = function getImagesAllList(req, res) { // strNum reqParam = req.body; pageNum = reqParam.pageNum; - startNum = (pageNum - 1) * 10; + startNum = (pageNum - 1) * MAX_IMAGE_PER_PAGE; queryString = _.template(_.join(this.queries['getImagesAllList'], ''))({ startNum: startNum diff --git a/controller/mic.js b/controller/mic.js index 2838e68..d8f220b 100644 --- a/controller/mic.js +++ b/controller/mic.js @@ -17,6 +17,9 @@ var AppConfig = require('../config.json'); var logger = JL('mic.js'); +var PROCESS_CNT_MAX = 1; +var PROCESS_CNT_MIN = 0; + var Mic = {}; /** @@ -29,8 +32,10 @@ var Mic = {}; */ var processMgr = []; +var user; + Mic.isAvailable = function isAvailable() { - if (processMgr.length > 0 && processMgr.length <= 4) { + if (processMgr.length > PROCESS_CNT_MIN && processMgr.length <= PROCESS_CNT_MAX) { return true; } return false; diff --git a/public/src/css/style.css b/public/src/css/style.css index a768a5b..09189af 100644 --- a/public/src/css/style.css +++ b/public/src/css/style.css @@ -173,7 +173,7 @@ body { display: inline-block; width: 100%; text-align: center; - overflow: scroll; + overflow: auto; } #tic-job-section .panel-heading .pull-right { margin-top: -20px; @@ -206,10 +206,6 @@ body { background-color: rgba(47, 45, 45, 0.48); opacity: 0.6; } -#tic-job-list .btncancel { - background-color: darkslategray; - cursor: pointer; -} .empty_job_table_row > td { height: 40px; overflow: hidden; @@ -245,6 +241,8 @@ tr.extended_job_table_row:hover td { text-align: center; height: 38px; vertical-align: middle; + background-color: rgba(51, 122, 183, 0.12); + color: steelblue; } #tic-job-list-pagination { @@ -266,7 +264,7 @@ tr.extended_job_table_row:hover td { #tic-image-list { height: calc(100vh - 285px); display: inline-block; - overflow: scroll; + overflow: auto; text-overflow: ellipsis; width: 100%; } @@ -316,12 +314,14 @@ tr.extended_job_table_row:hover td { .image-item-title { width: 100%; float: left; + height: 35px; } .image-item-info { width: 100%; float: left; display: table; padding-top: 20px; + height: 120px; } #tic-image-list-content { height: calc(100vh - 320px); diff --git a/public/src/js/model/JobModel.js b/public/src/js/model/JobModel.js index 4fbf389..04b51b2 100644 --- a/public/src/js/model/JobModel.js +++ b/public/src/js/model/JobModel.js @@ -51,6 +51,8 @@ define([ this.jobAbsLogPath = null; this.jobUptime = null; + this.jobUserGroup = null; + this.init(paramObj); return this; @@ -76,6 +78,8 @@ define([ this.setJobAbsLogPath(); this.setJobUptime(obj.job_uptime); + + this.setJobUserGroup(obj.job_usergroup); }; JobModel.prototype.getIsDownload = function () { @@ -94,6 +98,14 @@ define([ this.jobUptime = value; }; + JobModel.prototype.getJobUserGroup = function () { + return this.jobUserGroup; + }; + + JobModel.prototype.setJobUserGroup = function (value) { + this.jobUserGroup = value; + }; + JobModel.prototype.getJobLogPath = function () { return this.jobLogPath; }; diff --git a/public/src/js/page/job.js b/public/src/js/page/job.js index 5142c09..918981f 100644 --- a/public/src/js/page/job.js +++ b/public/src/js/page/job.js @@ -33,6 +33,9 @@ define([ // config var AppConfig; + // User + var UserInfo; + // the list for the job var ModelJobList = []; @@ -42,6 +45,7 @@ define([ // const var JOB_STATUS_DONE = 'DONE'; var JOB_STATUS_FAILED = 'FAILED'; + var USER_DEFAULT = 'GUEST'; function gotoPageNum(pageNum) { logger.info('gotoPageNum : ' + pageNum); @@ -95,7 +99,13 @@ define([ // model _.forEach(result, function (jobItem) { - var item = new JobModel(jobItem); + var item; + + // add the information of user's group + jobItem['job_usergroup'] = UserInfo.group || USER_DEFAULT; + + item = new JobModel(jobItem); + ModelJobList.push(item); }); @@ -174,42 +184,6 @@ define([ .then(_updateView); } - function updateList(selectedPageNum) { - logger.info('updateList'); - // when first, - // the default value of pageNum is 1. - var pageNum = selectedPageNum || 1; - gotoPageNum(pageNum); - } - - /** - * @name doCreateAnImage - * @param paramObj { - * jobId: '1', - * pathKsFile: '/var/tmp/tic-web/1/default.ks', - * pathOutput: '/var/tmp/tic-web/1/', - * imageName: 'default', - * imageArch: 'armv7l' - * } - */ - function doCreateAnImage(paramObj) { - var msgData; - - logger.info('doCreateAnImage'); - - msgData = { - jobId: paramObj.jobId, - pathKsFile: paramObj.pathKsFile, - pathOutput: paramObj.pathOutput, - imageName: paramObj.pathOutput + paramObj.imageName, - imageArch: paramObj.imageArch - }; - - client.emit(AppConfig.EVENT.SOCKET.FS_IMAGE_ADD_FROM, msgData); - - updateList(ModelJobPaging.getCurrentPoint()); - } - function _initSocket(socket) { // assign client = socket; @@ -382,6 +356,61 @@ define([ }); } + /** + * @name updateUserInfo + * @desc Set the user info. + */ + function updateUserInfo () { + /** + * TODO + * + * To be improved. + */ + Util.GET('api/session') + .then(function (user) { + UserInfo = user; + }); + } + + /** + * @name doCreateAnImage + * @param paramObj { + * jobId: '1', + * pathKsFile: '/var/tmp/tic-web/1/default.ks', + * pathOutput: '/var/tmp/tic-web/1/', + * imageName: 'default', + * imageArch: 'armv7l' + * } + */ + function doCreateAnImage(paramObj) { + var msgData; + + logger.info('doCreateAnImage'); + + msgData = { + jobId: paramObj.jobId, + pathKsFile: paramObj.pathKsFile, + pathOutput: paramObj.pathOutput, + imageName: paramObj.pathOutput + paramObj.imageName, + imageArch: paramObj.imageArch + }; + + client.emit(AppConfig.EVENT.SOCKET.FS_IMAGE_ADD_FROM, msgData); + + updateList(ModelJobPaging.getCurrentPoint()); + } + + /** + * @name updateList + */ + function updateList(selectedPageNum) { + logger.info('updateList'); + // when first, + // the default value of pageNum is 1. + var pageNum = selectedPageNum || 1; + gotoPageNum(pageNum); + } + function init() { logger.info('init'); @@ -390,6 +419,7 @@ define([ AppConfig = data; _initSocket(Util.getWebSocket()); updateList(); + updateUserInfo(); }); } @@ -406,7 +436,12 @@ define([ * Create an Image * @method doCreateAnImage */ - doCreateAnImage: doCreateAnImage + doCreateAnImage: doCreateAnImage, + + /** + * Set the user info. + */ + updateUserInfo: updateUserInfo } }); \ No newline at end of file diff --git a/public/src/js/widget/JobTableItem.js b/public/src/js/widget/JobTableItem.js index 4923d22..3f41058 100644 --- a/public/src/js/widget/JobTableItem.js +++ b/public/src/js/widget/JobTableItem.js @@ -43,6 +43,8 @@ define([ var JOB_STATUS_INPROGRESS = 'INPROGRESS'; var JOB_STATUS_DONE = 'DONE'; + var USER_GROUP_ADMIN = 'ADMIN'; + var USER_GROUP_MASTER = 'MASTER'; var JobTableItem = function (modelObj) { this.model = modelObj; @@ -63,6 +65,20 @@ define([ var data = item || this.model; var statusValue = data.getJobStatus(); + function getCssCancelbtn () { + var userGroup, cssCancelbtn; + userGroup = data.getJobUserGroup(); + cssCancelbtn = ''; + if (userGroup === USER_GROUP_ADMIN || userGroup === USER_GROUP_MASTER) { + if (statusValue !== JOB_STATUS_INPROGRESS) { + cssCancelbtn = 'btnnotactive'; + } + } else { + cssCancelbtn = 'btnnotactive'; + } + return cssCancelbtn; + } + function createRow () { var temp = _.template(_.join(strRow, '')); return temp({ @@ -73,7 +89,7 @@ define([ 'jobImageSize': data.getJobImageSize(), 'jobImagePath': data.getJobAbsImagePath(), 'classJobImageDownload': data.getJobStatus() === JOB_STATUS_DONE ? '' : 'btnnotactive', - 'classJobCancel': statusValue === JOB_STATUS_INPROGRESS ? '' : 'btnnotactive' , + 'classJobCancel': getCssCancelbtn() , 'classJobKsPath': data.getJobHasKsFile() === '0' ? 'btnnotactive' : '', 'jobKsPath': data.getJobAbsKsPath(), 'jobLogPath': data.getJobAbsLogPath(), @@ -90,7 +106,7 @@ define([ 'jobImageName': data.getJobImageName(), 'jobImageSize': data.getJobImageSize(), 'jobImagePath': data.getJobAbsImagePath(), - 'classJobCancel': statusValue === JOB_STATUS_INPROGRESS ? '' : 'btnnotactive' , + 'classJobCancel': getCssCancelbtn() , 'classJobKsPath': data.getJobHasKsFile() === '0' ? 'btnnotactive' : '', 'jobKsPath': data.getJobAbsKsPath(), 'jobLogPath': data.getJobAbsLogPath(), -- 2.7.4