[TIC-Web] Update The Section For The Job
[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.jobStatusClass = null;
36         this.jobImageName = null;
37         this.jobImageSize = null;
38         this.jobPath = null;
39         this.jobImagePath = null;
40         this.jobHasKsFile = false;
41         this.jobKsPath = null;
42         this.jobLogPath = null;
43         this.isDownload = false;
44
45         // for the href on a tag
46         this.jobAbsPath = null;
47         this.jobAbsImagePath = null;
48         this.jobAbsKsPath = null;
49         this.jobAbsLogPath = null;
50         this.jobUptime = null;
51
52         this.init(paramObj);
53
54         return this;
55     };
56
57     JobModel.prototype.init = function (obj) {
58         logger.info('init: ' + JSON.stringify(obj));
59
60         this.setJobId(obj.job_id);
61         this.setJobStatus(obj.job_status);
62         this.setJobImageName(obj.job_image_name);
63         this.setJobImageSize(obj.job_image_size);
64
65         this.setJobPath();
66         this.setJobImagePath();
67         this.setJobHasKsFile(obj.job_hasksfile);
68         this.setJobKsPath();
69         this.setJobLogPath();
70
71         this.setJobAbsPath();
72         this.setJobAbsImagePath();
73         this.setJobAbsKsPath();
74         this.setJobAbsLogPath();
75
76         this.setJobUptime(obj.job_uptime);
77     };
78
79     JobModel.prototype.getIsDownload = function () {
80         return this.isDownload;
81     };
82
83     JobModel.prototype.setIsDownload = function (value) {
84         this.isDownload = value || false;
85     };
86
87     JobModel.prototype.getJobUptime = function () {
88         return this.jobUptime;
89     };
90
91     JobModel.prototype.setJobUptime = function (value) {
92         this.jobUptime = value;
93     };
94
95     JobModel.prototype.getJobLogPath = function () {
96         return this.jobLogPath;
97     };
98
99     JobModel.prototype.setJobLogPath = function () {
100         this.jobLogPath = this.getJobPath() + AppConfig.TIC_WEB.LOG_FILE_NAME;
101     };
102
103     JobModel.prototype.getJobAbsLogPath = function () {
104         return this.jobAbsLogPath;
105     };
106
107     JobModel.prototype.setJobAbsLogPath = function () {
108         this.jobAbsLogPath = this.getJobAbsPath() + AppConfig.TIC_WEB.LOG_FILE_NAME;
109     };
110
111     JobModel.prototype.getJobKsPath = function () {
112         return this.jobKsPath;
113     };
114
115     JobModel.prototype.setJobKsPath = function () {
116         this.jobKsPath = this.getJobPath() + AppConfig.TIC_WEB.KS_FILE_NAME;
117     };
118
119     JobModel.prototype.getJobAbsKsPath = function () {
120         return this.jobAbsKsPath;
121     };
122
123     JobModel.prototype.setJobAbsKsPath = function () {
124         this.jobAbsKsPath = this.getJobAbsPath() + AppConfig.TIC_WEB.KS_FILE_NAME;
125     };
126
127     JobModel.prototype.getJobHasKsFile = function () {
128         return this.jobHasKsFile;
129     };
130
131     JobModel.prototype.setJobHasKsFile = function (value) {
132         this.jobHasKsFile = value || false;
133     };
134
135     JobModel.prototype.getJobImagePath = function () {
136         return this.jobImagePath;
137     };
138
139     JobModel.prototype.setJobImagePath = function () {
140         this.jobImagePath = this.getJobPath() + this.getJobImageName();
141     };
142
143     JobModel.prototype.getJobImageSize = function () {
144         return this.jobImageSize;
145     };
146
147     JobModel.prototype.setJobImageSize = function (value) {
148         this.jobImageSize = value ? Util.bytesToSize(value) : '0KB';
149     };
150
151     JobModel.prototype.getJobPath = function () {
152         return this.jobPath;
153     };
154
155     JobModel.prototype.setJobPath = function () {
156         this.jobPath = AppConfig.TIC_WEB.PATH + this.getJobId() + '/';
157     };
158
159     JobModel.prototype.getJobAbsImagePath = function () {
160         return this.jobAbsImagePath;
161     };
162
163     JobModel.prototype.setJobAbsImagePath = function () {
164         this.jobAbsImagePath = this.getJobAbsPath() + this.getJobImageName();
165     };
166
167     JobModel.prototype.getJobAbsPath = function () {
168         return this.jobAbsPath;
169     };
170
171     JobModel.prototype.setJobAbsPath = function () {
172         this.jobAbsPath = AppConfig.TIC_WEB.PATH_ABSTRACT + this.getJobId() + '/';
173     };
174
175     JobModel.prototype.getJobImageName = function () {
176         return this.jobImageName;
177     };
178
179     JobModel.prototype.setJobImageName = function (value) {
180         this.jobImageName = value ? value : '-';
181     };
182
183     JobModel.prototype.getJobStatusText = function () {
184         return this.jobStatusText;
185     };
186
187     JobModel.prototype.setJobStatusText = function (value) {
188         this.jobStatusText = value || '';
189     };
190
191     JobModel.prototype.getJobStatusClass = function (value) {
192         return this.jobStatusClass;
193     };
194
195     JobModel.prototype.setJobStatusClass = function (value) {
196         this.jobStatusClass = value || '';
197     };
198
199     JobModel.prototype.getJobStatus = function () {
200         return this.jobStatus;
201     };
202
203     JobModel.prototype.setJobStatus = function (status) {
204         var statusInfo, isDownloadable;
205
206         isDownloadable = false;
207         statusInfo = JobStatusModel.getStatusInfo(status);
208         /**
209          * statusInfo = {
210          *      value: 'READY',
211          *      text: 'Ready',
212          *      class: 'fa'
213          * }
214          */
215
216         this.jobStatus = statusInfo.value || '';
217         this.setJobStatusText(statusInfo.text);
218         this.setJobStatusClass(statusInfo.class);
219
220         if (this.getJobStatus() === DOWNLOADABLE_STATUS) {
221             isDownloadable = true;
222         }
223
224         this.setIsDownload(isDownloadable);
225     };
226
227     JobModel.prototype.getJobId = function () {
228         return this.jobId;
229     };
230
231     JobModel.prototype.setJobId = function (value) {
232         this.jobId = value || 0;
233     };
234
235     return JobModel;
236 });