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