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