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