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