1 | |
package org.kuali.student.lum.lu.ui.course.client.controllers; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.List; |
5 | |
|
6 | |
import org.kuali.student.common.assembly.data.Data; |
7 | |
import org.kuali.student.common.assembly.data.Metadata; |
8 | |
import org.kuali.student.common.dto.DtoConstants; |
9 | |
import org.kuali.student.common.ui.client.application.Application; |
10 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
11 | |
import org.kuali.student.common.ui.client.configurable.mvc.layouts.BasicLayoutWithContentHeader; |
12 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.HorizontalSection; |
13 | |
import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView; |
14 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
15 | |
import org.kuali.student.common.ui.client.mvc.Controller; |
16 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
17 | |
import org.kuali.student.common.ui.client.mvc.DataModelDefinition; |
18 | |
import org.kuali.student.common.ui.client.mvc.ModelProvider; |
19 | |
import org.kuali.student.common.ui.client.mvc.ModelRequestCallback; |
20 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
21 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
22 | |
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; |
23 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotification; |
24 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotifier; |
25 | |
import org.kuali.student.common.ui.client.widgets.progress.BlockingTask; |
26 | |
import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator; |
27 | |
import org.kuali.student.core.statement.dto.StatementTypeInfo; |
28 | |
import org.kuali.student.lum.common.client.lu.LUUIConstants; |
29 | |
import org.kuali.student.lum.lu.ui.course.client.configuration.CourseSummaryConfigurer; |
30 | |
import org.kuali.student.lum.lu.ui.course.client.requirements.CourseRequirementsDataModel; |
31 | |
import org.kuali.student.lum.lu.ui.course.client.requirements.HasRequirements; |
32 | |
import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcService; |
33 | |
import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcServiceAsync; |
34 | |
import org.kuali.student.lum.lu.ui.course.client.views.SelectVersionsView; |
35 | |
import org.kuali.student.lum.lu.ui.course.client.views.ShowVersionView; |
36 | |
import org.kuali.student.lum.lu.ui.course.client.widgets.CourseWorkflowActionList; |
37 | |
|
38 | |
import com.google.gwt.core.client.GWT; |
39 | |
import com.google.gwt.event.dom.client.ClickEvent; |
40 | |
import com.google.gwt.event.dom.client.ClickHandler; |
41 | |
import com.google.gwt.user.client.Window; |
42 | |
import com.google.gwt.user.client.ui.Widget; |
43 | |
|
44 | 0 | public class VersionsController extends BasicLayoutWithContentHeader implements HasRequirements{ |
45 | |
|
46 | 0 | public static enum Views{VERSION_SELECT, VERSION_VIEW, VERSION_COMPARE} |
47 | |
|
48 | 0 | private SelectVersionsView select = new SelectVersionsView(this, "", Views.VERSION_SELECT); |
49 | |
private ShowVersionView view; |
50 | |
private VerticalSectionView compare; |
51 | |
private static final String MSG_GROUP = "course"; |
52 | 0 | private String type = "course"; |
53 | 0 | private String state = DtoConstants.STATE_DRAFT; |
54 | 0 | private String groupName = LUUIConstants.COURSE_GROUP_NAME; |
55 | |
CourseSummaryConfigurer summaryConfigurer; |
56 | 0 | CourseRpcServiceAsync rpcServiceAsync = GWT.create(CourseRpcService.class); |
57 | |
DataModelDefinition definition; |
58 | |
|
59 | |
private DataModel cluModel1; |
60 | |
private DataModel cluModel2; |
61 | |
|
62 | 0 | private String lastId1 = ""; |
63 | 0 | private String lastId2 = ""; |
64 | 0 | private HorizontalSection workflowVersionInfoSection = new HorizontalSection(); |
65 | |
|
66 | |
private final CourseRequirementsDataModel reqDataModel1; |
67 | |
private final CourseRequirementsDataModel reqDataModel2; |
68 | |
|
69 | 0 | private boolean initialized = false; |
70 | 0 | private String versionIndId = ""; |
71 | 0 | private String currentVersionId = ""; |
72 | 0 | private final BlockingTask loadDataTask = new BlockingTask("Retrieving Data...."); |
73 | |
|
74 | 0 | private List<CourseWorkflowActionList> actionDropDownWidgets = new ArrayList<CourseWorkflowActionList>(); |
75 | 0 | private KSLabel statusLabel = new KSLabel(""); |
76 | |
|
77 | |
public VersionsController(Enum<?> viewType) { |
78 | 0 | super(VersionsController.class.toString()); |
79 | 0 | this.addView(select); |
80 | 0 | this.setDefaultView(Views.VERSION_SELECT); |
81 | 0 | this.setName("Versions"); |
82 | 0 | this.setViewEnum(viewType); |
83 | 0 | KSButton versionHistoryButton = new KSButton("Version History", ButtonStyle.DEFAULT_ANCHOR, new ClickHandler(){ |
84 | |
|
85 | |
@Override |
86 | |
public void onClick(ClickEvent event) { |
87 | 0 | VersionsController.this.showDefaultView(Controller.NO_OP_CALLBACK); |
88 | 0 | } |
89 | |
}); |
90 | 0 | versionHistoryButton.addStyleName("versionHistoryLink"); |
91 | |
|
92 | 0 | reqDataModel1 = new CourseRequirementsDataModel(this); |
93 | 0 | reqDataModel2 = new CourseRequirementsDataModel(this); |
94 | |
|
95 | 0 | workflowVersionInfoSection.addWidget(this.getStatusLabel()); |
96 | 0 | workflowVersionInfoSection.addWidget(this.generateActionDropDown()); |
97 | 0 | workflowVersionInfoSection.addWidget(versionHistoryButton); |
98 | |
|
99 | 0 | this.getHeader().addWidget(workflowVersionInfoSection); |
100 | 0 | this.viewContainer.addStyleName("standard-content-padding"); |
101 | 0 | initialize(); |
102 | 0 | } |
103 | |
|
104 | |
public void setVersionIndId(String versionIndId) { |
105 | 0 | this.versionIndId = versionIndId; |
106 | 0 | } |
107 | |
|
108 | |
private void initialize() { |
109 | 0 | super.setDefaultModelId("Model"); |
110 | 0 | super.registerModel("Model", new ModelProvider<DataModel>() { |
111 | |
|
112 | |
@Override |
113 | |
public void requestModel(final ModelRequestCallback<DataModel> callback) { |
114 | 0 | if(getViewContext().getId() != null && !getViewContext().getId().isEmpty()){ |
115 | 0 | getCourseFromCluId(getViewContext().getId(), 1, callback, true); |
116 | |
} |
117 | |
else{ |
118 | 0 | callback.onModelReady(null); |
119 | |
} |
120 | 0 | } |
121 | |
}); |
122 | |
|
123 | 0 | super.registerModel("ComparisonModel", new ModelProvider<DataModel>() { |
124 | |
@Override |
125 | |
public void requestModel(final ModelRequestCallback<DataModel> callback) { |
126 | 0 | if(getViewContext().getAttribute("docId2") != null && !getViewContext().getAttribute("docId2").isEmpty()){ |
127 | 0 | getCourseFromCluId(getViewContext().getAttribute("docId2"), 2, callback, false); |
128 | |
} |
129 | |
else{ |
130 | 0 | callback.onModelReady(null); |
131 | |
} |
132 | 0 | } |
133 | |
}); |
134 | 0 | } |
135 | |
|
136 | |
@SuppressWarnings("unchecked") |
137 | |
private void getCourseFromCluId(final String courseId, final int modelNum, final ModelRequestCallback callback, final boolean id1Model){ |
138 | 0 | KSBlockingProgressIndicator.addTask(loadDataTask); |
139 | |
|
140 | 0 | rpcServiceAsync.getData(courseId, new KSAsyncCallback<Data>(){ |
141 | |
|
142 | |
@Override |
143 | |
public void handleFailure(Throwable caught) { |
144 | 0 | Window.alert("Error loading Course: "+caught.getMessage()); |
145 | 0 | callback.onRequestFail(caught); |
146 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
147 | 0 | } |
148 | |
|
149 | |
@Override |
150 | |
public void onSuccess(Data result) { |
151 | 0 | if(modelNum == 1){ |
152 | 0 | cluModel1 = new DataModel(); |
153 | 0 | cluModel1.setDefinition(definition); |
154 | 0 | cluModel1.setRoot(result); |
155 | 0 | if(courseId.equals(currentVersionId)){ |
156 | 0 | String name = "Version " + cluModel1.get("versionInfo/sequenceNumber") + " (current version)"; |
157 | 0 | cluModel1.setModelName(name); |
158 | 0 | view.setName(name); |
159 | 0 | view.showWarningMessage(false); |
160 | 0 | } |
161 | |
else{ |
162 | 0 | String name = "Version " + cluModel1.get("versionInfo/sequenceNumber"); |
163 | 0 | cluModel1.setModelName(name); |
164 | 0 | view.setName(name); |
165 | 0 | view.showWarningMessage(true); |
166 | |
} |
167 | 0 | updateState(cluModel1); |
168 | |
|
169 | 0 | reqDataModel1.retrieveStatementTypes(cluModel1.<String>get("id"), new Callback<Boolean>() { |
170 | |
@Override |
171 | |
public void exec(Boolean result) { |
172 | 0 | if (result) { |
173 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
174 | 0 | callback.onModelReady(cluModel1); |
175 | |
} |
176 | 0 | } |
177 | |
}); |
178 | |
} |
179 | |
else{ |
180 | 0 | cluModel2 = new DataModel(); |
181 | 0 | cluModel2.setDefinition(definition); |
182 | 0 | cluModel2.setRoot(result); |
183 | 0 | if(courseId.equals(currentVersionId)){ |
184 | 0 | cluModel2.setModelName("Version " + cluModel2.get("versionInfo/sequenceNumber") + " (current version)"); |
185 | |
} |
186 | |
else{ |
187 | 0 | cluModel2.setModelName("Version " + cluModel2.get("versionInfo/sequenceNumber")); |
188 | |
} |
189 | |
|
190 | 0 | reqDataModel2.retrieveStatementTypes(cluModel2.<String>get("id"), new Callback<Boolean>() { |
191 | |
@Override |
192 | |
public void exec(Boolean result) { |
193 | 0 | if (result) { |
194 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
195 | 0 | callback.onModelReady(cluModel2); |
196 | |
} |
197 | 0 | } |
198 | |
}); |
199 | |
} |
200 | 0 | } |
201 | |
}); |
202 | 0 | } |
203 | |
|
204 | |
@Override |
205 | |
public void showDefaultView(final Callback<Boolean> onReadyCallback) { |
206 | 0 | KSBlockingProgressIndicator.addTask(loadDataTask); |
207 | |
|
208 | 0 | init(new Callback<Boolean>() { |
209 | |
|
210 | |
@Override |
211 | |
public void exec(Boolean result) { |
212 | 0 | if (result) { |
213 | 0 | VersionsController.super.showDefaultView(new Callback<Boolean>() { |
214 | |
|
215 | |
@Override |
216 | |
public void exec(Boolean result) { |
217 | 0 | onReadyCallback.exec(result); |
218 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
219 | 0 | } |
220 | |
}); |
221 | |
} else { |
222 | 0 | onReadyCallback.exec(false); |
223 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
224 | |
} |
225 | |
|
226 | 0 | } |
227 | |
}); |
228 | 0 | } |
229 | |
|
230 | |
@Override |
231 | |
public void beforeShow(Callback<Boolean> onReadyCallback) { |
232 | 0 | workflowVersionInfoSection.setVisible(false); |
233 | 0 | this.getHeader().showPrint(false); |
234 | 0 | this.getHeader().showExport(false); |
235 | 0 | showDefaultView(onReadyCallback); |
236 | 0 | } |
237 | |
|
238 | |
private void init(final Callback<Boolean> onReadyCallback) { |
239 | |
|
240 | 0 | if (initialized) { |
241 | 0 | onReadyCallback.exec(true); |
242 | |
} else { |
243 | 0 | KSBlockingProgressIndicator.addTask(loadDataTask); |
244 | |
|
245 | 0 | rpcServiceAsync.getMetadata("", null, new KSAsyncCallback<Metadata>(){ |
246 | |
|
247 | |
public void handleFailure(Throwable caught) { |
248 | 0 | initialized = false; |
249 | 0 | onReadyCallback.exec(false); |
250 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
251 | 0 | throw new RuntimeException("Failed to get model definition.", caught); |
252 | |
} |
253 | |
|
254 | |
public void onSuccess(Metadata result) { |
255 | 0 | definition = new DataModelDefinition(result); |
256 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
257 | 0 | configureScreens(onReadyCallback); |
258 | 0 | } |
259 | |
}); |
260 | |
|
261 | |
} |
262 | 0 | } |
263 | |
|
264 | |
private void configureScreens(final Callback<Boolean> onReadyCallback) { |
265 | 0 | CourseRequirementsDataModel.getStatementTypes(new Callback<List<StatementTypeInfo>>() { |
266 | |
|
267 | |
@Override |
268 | |
public void exec(List<StatementTypeInfo> stmtTypes) { |
269 | 0 | List<StatementTypeInfo> stmtTypesOut = new ArrayList<StatementTypeInfo>(); |
270 | 0 | if (stmtTypes != null) { |
271 | 0 | for (StatementTypeInfo stmtType : stmtTypes) { |
272 | 0 | if (stmtType.getId().contains("kuali.statement.type.course.enrollmentEligibility") || |
273 | |
stmtType.getId().contains("kuali.statement.type.course.creditConstraints")) { |
274 | 0 | continue; |
275 | |
} |
276 | 0 | stmtTypesOut.add(stmtType); |
277 | |
} |
278 | |
} |
279 | |
|
280 | 0 | summaryConfigurer = new CourseSummaryConfigurer(type, state, groupName, definition, stmtTypesOut, VersionsController.this, "Model"); |
281 | 0 | view = new ShowVersionView(Views.VERSION_VIEW, "Version", "Model", VersionsController.this, stmtTypesOut); |
282 | 0 | compare = summaryConfigurer.generateCourseSummarySection(); |
283 | 0 | compare.setLayoutController(VersionsController.this); |
284 | 0 | compare.setSectionTitle("Compare Versions"); |
285 | 0 | compare.setName("Compare Versions"); |
286 | 0 | compare.setViewEnum(Views.VERSION_COMPARE); |
287 | 0 | VersionsController.this.addView(view); |
288 | 0 | VersionsController.this.addView(compare); |
289 | 0 | initialized = true; |
290 | 0 | onReadyCallback.exec(true); |
291 | 0 | } |
292 | |
}); |
293 | 0 | } |
294 | |
|
295 | |
public Widget generateActionDropDown(){ |
296 | 0 | CourseWorkflowActionList actionList = new CourseWorkflowActionList(this.getMessage("cluActionsLabel")); |
297 | |
|
298 | 0 | actionDropDownWidgets.add(actionList); |
299 | |
|
300 | 0 | return actionList; |
301 | |
} |
302 | |
|
303 | |
private void updateState(final DataModel cluModel) { |
304 | 0 | if(cluModel.get("state") != null){ |
305 | 0 | statusLabel.setText("Status: " + cluModel.get("state")); |
306 | |
|
307 | 0 | for(CourseWorkflowActionList widget: actionDropDownWidgets){ |
308 | 0 | widget.init(getViewContext(), "/HOME/CURRICULUM_HOME/COURSE_PROPOSAL", cluModel, new Callback<String>() { |
309 | |
@Override |
310 | |
public void exec(String newState) { |
311 | 0 | if (newState != null) { |
312 | 0 | KSNotifier.add(new KSNotification(getMessage("cluStateChangeNotification" + newState), false, 5000)); |
313 | |
|
314 | 0 | statusLabel.setText("Status: " + newState); |
315 | |
} else { |
316 | 0 | KSNotifier.add(new KSNotification(getMessage("cluStateChangeFailedNotification"), false, 5000)); |
317 | |
} |
318 | 0 | } |
319 | |
}); |
320 | 0 | widget.updateCourseActionItems(cluModel); |
321 | |
|
322 | |
} |
323 | |
} |
324 | 0 | } |
325 | |
|
326 | |
public Widget getStatusLabel() { |
327 | 0 | statusLabel.setStyleName("courseStatusLabel"); |
328 | 0 | return statusLabel; |
329 | |
} |
330 | |
|
331 | |
public DataModelDefinition getDefinition(){ |
332 | 0 | return definition; |
333 | |
} |
334 | |
|
335 | |
public void setCurrentVersionId(String id) { |
336 | 0 | this.currentVersionId = id; |
337 | 0 | } |
338 | |
|
339 | |
public String getCurrentVersionId() { |
340 | 0 | return currentVersionId; |
341 | |
} |
342 | |
|
343 | |
public String getVersionIndId() { |
344 | 0 | return versionIndId; |
345 | |
} |
346 | |
|
347 | |
public String getMessage(String courseMessageKey) { |
348 | 0 | String msg = Application.getApplicationContext().getMessage(MSG_GROUP, courseMessageKey); |
349 | 0 | if (msg == null) { |
350 | 0 | msg = courseMessageKey; |
351 | |
} |
352 | 0 | return msg; |
353 | |
} |
354 | |
|
355 | |
|
356 | |
@Override |
357 | |
public <V extends Enum<?>> void showView(V viewType, Callback<Boolean> onReadyCallback) { |
358 | 0 | if(viewType != Views.VERSION_SELECT){ |
359 | 0 | workflowVersionInfoSection.setVisible(true); |
360 | 0 | this.getHeader().showPrint(true); |
361 | 0 | this.getHeader().showExport(true); |
362 | |
} |
363 | |
else{ |
364 | 0 | workflowVersionInfoSection.setVisible(false); |
365 | 0 | this.getHeader().showPrint(false); |
366 | 0 | this.getHeader().showExport(false); |
367 | |
} |
368 | 0 | super.showView(viewType, onReadyCallback); |
369 | 0 | } |
370 | |
|
371 | |
|
372 | |
|
373 | |
public void setCurrentTitle(String currentTitle) { |
374 | 0 | this.getHeader().setTitle(currentTitle); |
375 | 0 | } |
376 | |
|
377 | |
|
378 | |
@Override |
379 | |
public CourseRequirementsDataModel getReqDataModel() { |
380 | 0 | return reqDataModel1; |
381 | |
} |
382 | |
|
383 | |
public CourseRequirementsDataModel getReqDataModelComp() { |
384 | 0 | return reqDataModel2; |
385 | |
} |
386 | |
} |