[TIC-Web] source clean up
[archive/20170607/tools/tic.git] / public / src / js / model / JobModel.js
1 define([
2     'jquery',
3     'lodash',
4     'js/util',
5     'js/logger'
6 ], function (
7     $,
8     _,
9     Util,
10     Logger
11 ) {
12     'use strict';
13
14     var logger = Logger('model/JobModel.js');
15
16     // config
17     var AppConfig = null;
18
19     // define the downloadable status
20     var DOWNLOADABLE_STATUS = 'DONE';
21     // define the default status
22     var DEFAULT_STATUS = 'READY';
23
24     // describe the all the status of job
25     var JOB_STATUS_LIST = [
26         {
27             value: 'READY',
28             text: 'Ready'
29         },
30         {
31             value: 'DONE', 
32             text: 'Done'
33         },
34         {
35             value: 'CANCELED',
36             text: 'Canceled'
37         },
38         {
39             value: 'FAILED',
40             text: 'Failed'
41         },
42         {
43             value: 'INPROGRESS',
44             text: 'In Progress'
45         }
46     ];
47
48     // set the config information for the app
49     Util.getAppConfig().then(function (data) {
50         AppConfig = data;
51     });
52
53     var JobModel = function (paramObj) {
54         this.jobId;
55         this.jobStatus;
56         this.jobStatusText;
57         this.jobImageName;
58         this.jobImageSize;
59         this.jobPath;
60         this.jobImagePath;
61         this.jobHasKsFile = false;
62         this.jobKsPath;
63         this.jobLogPath;
64         this.isDownload;//{boolean}
65
66         // for the href on a tag
67         this.jobAbsPath;
68         this.jobAbsImagePath;
69         this.jobAbsKsPath;
70         this.jobAbsLogPath;
71         this.jobUptime;
72
73         this.init(paramObj);
74
75         return this;
76     };
77
78     JobModel.prototype.init = function (obj) {
79         logger.info('init: ' + JSON.stringify(obj));
80
81         this.setJobId(obj.job_id);
82         this.setJobStatus(obj.job_status);
83         this.setJobImageName(obj.job_image_name);
84         this.setJobImageSize(obj.job_image_size);
85
86         this.setJobPath();
87         this.setJobImagePath();
88         this.setJobHasKsFile(obj.job_hasksfile);
89         this.setJobKsPath();
90         this.setJobLogPath();
91
92         this.setJobAbsPath();
93         this.setJobAbsImagePath();
94         this.setJobAbsKsPath();
95         this.setJobAbsLogPath();
96
97         this.setJobUptime(obj.job_uptime);
98     };
99
100     JobModel.prototype.getIsDownload = function () {
101         return this.isDownload;
102     };
103
104     JobModel.prototype.setIsDownload = function (value) {
105         this.isDownload = value || false;
106     };
107
108     JobModel.prototype.getJobUptime = function () {
109         return this.jobUptime;
110     };
111
112     JobModel.prototype.setJobUptime = function (value) {
113         this.jobUptime = value;
114     };
115
116     JobModel.prototype.getJobLogPath = function () {
117         return this.jobLogPath;
118     };
119
120     JobModel.prototype.setJobLogPath = function () {
121         this.jobLogPath = this.getJobPath() + AppConfig.TIC_WEB.LOG_FILE_NAME;
122     };
123
124     JobModel.prototype.getJobAbsLogPath = function () {
125         return this.jobAbsLogPath;
126     };
127
128     JobModel.prototype.setJobAbsLogPath = function () {
129         this.jobAbsLogPath = this.getJobAbsPath() + AppConfig.TIC_WEB.LOG_FILE_NAME;
130     };
131
132     JobModel.prototype.getJobKsPath = function () {
133         return this.jobKsPath;
134     };
135
136     JobModel.prototype.setJobKsPath = function () {
137         this.jobKsPath = this.getJobPath() + AppConfig.TIC_WEB.KS_FILE_NAME;
138     };
139
140     JobModel.prototype.getJobAbsKsPath = function () {
141         return this.jobAbsKsPath;
142     };
143
144     JobModel.prototype.setJobAbsKsPath = function () {
145         this.jobAbsKsPath = this.getJobAbsPath() + AppConfig.TIC_WEB.KS_FILE_NAME;
146     };
147
148     JobModel.prototype.getJobHasKsFile = function () {
149         this.jobHasKsFile;
150     };
151
152     JobModel.prototype.setJobHasKsFile = function (value) {
153         this.jobHasKsFile = value || false;
154     };
155
156     JobModel.prototype.getJobImagePath = function () {
157         return this.jobImagePath;
158     };
159
160     JobModel.prototype.setJobImagePath = function () {
161         this.jobImagePath = this.getJobPath() + this.getJobImageName();
162     };
163
164     JobModel.prototype.getJobImageSize = function () {
165         return this.jobImageSize;
166     };
167
168     JobModel.prototype.setJobImageSize = function (value) {
169         this.jobImageSize = value ? Util.bytesToSize(value) : '0KB';
170     };
171
172     JobModel.prototype.getJobPath = function () {
173         return this.jobPath;
174     };
175
176     JobModel.prototype.setJobPath = function () {
177         this.jobPath = AppConfig.TIC_WEB.PATH + this.getJobId() + '/';
178     };
179
180     JobModel.prototype.getJobAbsImagePath = function () {
181         return this.jobAbsImagePath;
182     };
183
184     JobModel.prototype.setJobAbsImagePath = function () {
185         this.jobAbsImagePath = this.getJobAbsPath() + this.getJobImageName();
186     };
187
188     JobModel.prototype.getJobAbsPath = function () {
189         return this.jobAbsPath;
190     };
191
192     JobModel.prototype.setJobAbsPath = function () {
193         this.jobAbsPath = AppConfig.TIC_WEB.PATH_ABSTRACT + this.getJobId() + '/';
194     };
195
196     JobModel.prototype.getJobImageName = function () {
197         return this.jobImageName;
198     };
199
200     JobModel.prototype.setJobImageName = function (value) {
201         this.jobImageName = value ? value : '-';
202     };
203
204     JobModel.prototype.getJobStatusText = function () {
205         return this.jobStatusText;
206     };
207
208     JobModel.prototype.setJobStatusText = function (value) {
209         this.jobStatusText = value || '';
210     };
211
212     JobModel.prototype.getJobStatus = function () {
213         return this.jobStatus;
214     };
215
216     JobModel.prototype.setJobStatus = function (status) {
217         var statusInfo, isDownloadable;
218
219         isDownloadable = false;
220         statusInfo = _.find(JOB_STATUS_LIST, {value: status}) || _.find(JOB_STATUS_LIST, {value: DEFAULT_STATUS});
221
222         this.jobStatus = statusInfo.value || '';
223         this.setJobStatusText(statusInfo.text);
224
225         if (this.getJobStatus() === DOWNLOADABLE_STATUS) {
226             isDownloadable = true;
227         }
228
229         this.setIsDownload(isDownloadable);
230     };
231
232     JobModel.prototype.getJobId = function () {
233         return this.jobId;
234     };
235
236     JobModel.prototype.setJobId = function (value) {
237         this.jobId = value || 0;
238     };
239
240     return JobModel;
241 });