[TIC-Web] Update Job List
[archive/20170607/tools/tic.git] / public / src / js / model / JobModel.js
index ef1a015..4fbf389 100644 (file)
@@ -2,12 +2,14 @@ define([
     'jquery',
     'lodash',
     'js/util',
-    'js/logger'
+    'js/logger',
+    './JobStatusModel'
 ], function (
     $,
     _,
     Util,
-    Logger
+    Logger,
+    JobStatusModel
 ) {
     'use strict';
 
@@ -21,54 +23,33 @@ define([
     // define the default status
     var DEFAULT_STATUS = 'READY';
 
-    // describe the all the status of job
-    var JOB_STATUS_LIST = [
-        {
-            value: 'READY',
-            text: 'Ready'
-        },
-        {
-            value: 'DONE', 
-            text: 'Done'
-        },
-        {
-            value: 'CANCELED',
-            text: 'Canceled'
-        },
-        {
-            value: 'FAILED',
-            text: 'Failed'
-        },
-        {
-            value: 'INPROGRESS',
-            text: 'In Progress'
-        }
-    ];
-
     // set the config information for the app
     Util.getAppConfig().then(function (data) {
         AppConfig = data;
     });
 
     var JobModel = function (paramObj) {
-        this.jobId;
-        this.jobStatus;
-        this.jobStatusText;
-        this.jobImageName;
-        this.jobImageSize;
-        this.jobPath;
-        this.jobImagePath;
+        this.jobId = null;
+        this.jobStatus = null;
+        this.jobStatusText = null;
+        this.jobStatusClass = null;
+        this.jobImageName = null;
+        this.jobImageSize = null;
+        this.jobPath = null;
+        this.jobImagePath = null;
         this.jobHasKsFile = false;
-        this.jobKsPath;
-        this.jobLogPath;
-        this.isDownload;//{boolean}
+        this.jobKs = null;
+        this.jobKsPath = null;
+        this.jobLogPath = null;
+        this.jobArch = null;
+        this.isDownload = false;
 
         // for the href on a tag
-        this.jobAbsPath;
-        this.jobAbsImagePath;
-        this.jobAbsKsPath;
-        this.jobAbsLogPath;
-        this.jobUptime;
+        this.jobAbsPath = null;
+        this.jobAbsImagePath = null;
+        this.jobAbsKsPath = null;
+        this.jobAbsLogPath = null;
+        this.jobUptime = null;
 
         this.init(paramObj);
 
@@ -79,19 +60,19 @@ define([
         logger.info('init: ' + JSON.stringify(obj));
 
         this.setJobId(obj.job_id);
+        this.setJobAbsPath();
+        this.setJobPath();
+
         this.setJobStatus(obj.job_status);
         this.setJobImageName(obj.job_image_name);
         this.setJobImageSize(obj.job_image_size);
 
-        this.setJobPath();
-        this.setJobImagePath();
         this.setJobHasKsFile(obj.job_hasksfile);
-        this.setJobKsPath();
+        this.setJobKs(obj.job_ks);
+
         this.setJobLogPath();
+        this.setJobArch(obj.job_arch);
 
-        this.setJobAbsPath();
-        this.setJobAbsImagePath();
-        this.setJobAbsKsPath();
         this.setJobAbsLogPath();
 
         this.setJobUptime(obj.job_uptime);
@@ -121,6 +102,19 @@ define([
         this.jobLogPath = this.getJobPath() + AppConfig.TIC_WEB.LOG_FILE_NAME;
     };
 
+    JobModel.prototype.getJobArch = function () {
+        return this.jobArch;
+    };
+
+    JobModel.prototype.setJobArch = function (value) {
+        /**
+         * FIXME
+         *
+         * Confirm default value . armv7l right?
+         */
+        this.jobArch = value || 'armv7l';
+    };
+
     JobModel.prototype.getJobAbsLogPath = function () {
         return this.jobAbsLogPath;
     };
@@ -134,7 +128,7 @@ define([
     };
 
     JobModel.prototype.setJobKsPath = function () {
-        this.jobKsPath = this.getJobPath() + AppConfig.TIC_WEB.KS_FILE_NAME;
+        this.jobKsPath = this.getJobPath() + this.getJobKs();
     };
 
     JobModel.prototype.getJobAbsKsPath = function () {
@@ -142,17 +136,28 @@ define([
     };
 
     JobModel.prototype.setJobAbsKsPath = function () {
-        this.jobAbsKsPath = this.getJobAbsPath() + AppConfig.TIC_WEB.KS_FILE_NAME;
+        this.jobAbsKsPath = this.getJobAbsPath() + this.getJobKs();
     };
 
     JobModel.prototype.getJobHasKsFile = function () {
-        this.jobHasKsFile;
+        return this.jobHasKsFile;
     };
 
     JobModel.prototype.setJobHasKsFile = function (value) {
         this.jobHasKsFile = value || false;
     };
 
+    JobModel.prototype.getJobKs = function () {
+        return this.jobKs;
+    };
+
+    JobModel.prototype.setJobKs = function (value) {
+        this.jobKs = value || '';
+
+        this.setJobKsPath();
+        this.setJobAbsKsPath();
+    };
+
     JobModel.prototype.getJobImagePath = function () {
         return this.jobImagePath;
     };
@@ -198,7 +203,10 @@ define([
     };
 
     JobModel.prototype.setJobImageName = function (value) {
-        this.jobImageName = value ? value : '-';
+        this.jobImageName = value || '-';
+
+        this.setJobImagePath();
+        this.setJobAbsImagePath();
     };
 
     JobModel.prototype.getJobStatusText = function () {
@@ -209,6 +217,14 @@ define([
         this.jobStatusText = value || '';
     };
 
+    JobModel.prototype.getJobStatusClass = function (value) {
+        return this.jobStatusClass;
+    };
+
+    JobModel.prototype.setJobStatusClass = function (value) {
+        this.jobStatusClass = value || '';
+    };
+
     JobModel.prototype.getJobStatus = function () {
         return this.jobStatus;
     };
@@ -217,10 +233,18 @@ define([
         var statusInfo, isDownloadable;
 
         isDownloadable = false;
-        statusInfo = _.find(JOB_STATUS_LIST, {value: status}) || _.find(JOB_STATUS_LIST, {value: DEFAULT_STATUS});
+        statusInfo = JobStatusModel.getStatusInfo(status);
+        /**
+         * statusInfo = {
+         *      value: 'READY',
+         *      text: 'Ready',
+         *      class: 'fa'
+         * }
+         */
 
         this.jobStatus = statusInfo.value || '';
         this.setJobStatusText(statusInfo.text);
+        this.setJobStatusClass(statusInfo.class);
 
         if (this.getJobStatus() === DOWNLOADABLE_STATUS) {
             isDownloadable = true;