| 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 | showDefaultView(onReadyCallback); |
| 216 | 0 | } |
| 217 | |
|
| 218 | |
private void init(final Callback<Boolean> onReadyCallback) { |
| 219 | |
|
| 220 | 0 | if (initialized) { |
| 221 | 0 | onReadyCallback.exec(true); |
| 222 | |
} else { |
| 223 | 0 | KSBlockingProgressIndicator.addTask(loadDataTask); |
| 224 | |
|
| 225 | 0 | rpcServiceAsync.getMetadata("", null, new KSAsyncCallback<Metadata>(){ |
| 226 | |
|
| 227 | |
public void handleFailure(Throwable caught) { |
| 228 | 0 | initialized = false; |
| 229 | 0 | onReadyCallback.exec(false); |
| 230 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
| 231 | 0 | throw new RuntimeException("Failed to get model definition.", caught); |
| 232 | |
} |
| 233 | |
|
| 234 | |
public void onSuccess(Metadata result) { |
| 235 | 0 | definition = new DataModelDefinition(result); |
| 236 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
| 237 | 0 | configureScreens(onReadyCallback); |
| 238 | 0 | } |
| 239 | |
}); |
| 240 | |
|
| 241 | |
} |
| 242 | 0 | } |
| 243 | |
|
| 244 | |
private void configureScreens(final Callback<Boolean> onReadyCallback) { |
| 245 | 0 | CourseRequirementsDataModel.getStatementTypes(new Callback<List<StatementTypeInfo>>() { |
| 246 | |
|
| 247 | |
@Override |
| 248 | |
public void exec(List<StatementTypeInfo> stmtTypes) { |
| 249 | 0 | List<StatementTypeInfo> stmtTypesOut = new ArrayList<StatementTypeInfo>(); |
| 250 | 0 | if (stmtTypes != null) { |
| 251 | 0 | for (StatementTypeInfo stmtType : stmtTypes) { |
| 252 | 0 | if (stmtType.getId().contains("kuali.statement.type.course.enrollmentEligibility") || |
| 253 | |
stmtType.getId().contains("kuali.statement.type.course.creditConstraints")) { |
| 254 | 0 | continue; |
| 255 | |
} |
| 256 | 0 | stmtTypesOut.add(stmtType); |
| 257 | |
} |
| 258 | |
} |
| 259 | |
|
| 260 | 0 | summaryConfigurer = new CourseSummaryConfigurer(type, state, groupName, definition, stmtTypesOut, VersionsController.this, "Model"); |
| 261 | 0 | view = new ShowVersionView(Views.VERSION_VIEW, "Version", "Model", VersionsController.this, stmtTypesOut); |
| 262 | 0 | compare = summaryConfigurer.generateCourseSummarySection(); |
| 263 | 0 | compare.setLayoutController(VersionsController.this); |
| 264 | 0 | compare.setSectionTitle("Compare Versions"); |
| 265 | 0 | compare.setName("Compare Versions"); |
| 266 | 0 | compare.setViewEnum(Views.VERSION_COMPARE); |
| 267 | 0 | VersionsController.this.addView(view); |
| 268 | 0 | VersionsController.this.addView(compare); |
| 269 | 0 | initialized = true; |
| 270 | 0 | onReadyCallback.exec(true); |
| 271 | 0 | } |
| 272 | |
}); |
| 273 | 0 | } |
| 274 | |
|
| 275 | |
public Widget generateActionDropDown(){ |
| 276 | 0 | CourseWorkflowActionList actionList = new CourseWorkflowActionList(this.getMessage("cluActionsLabel")); |
| 277 | |
|
| 278 | 0 | actionDropDownWidgets.add(actionList); |
| 279 | |
|
| 280 | 0 | return actionList; |
| 281 | |
} |
| 282 | |
|
| 283 | |
private void updateState(final DataModel cluModel) { |
| 284 | 0 | if(cluModel.get("state") != null){ |
| 285 | 0 | statusLabel.setText("Status: " + cluModel.get("state")); |
| 286 | |
|
| 287 | 0 | for(CourseWorkflowActionList widget: actionDropDownWidgets){ |
| 288 | 0 | widget.init(getViewContext(), "/HOME/CURRICULUM_HOME/COURSE_PROPOSAL", cluModel, new Callback<String>() { |
| 289 | |
@Override |
| 290 | |
public void exec(String newState) { |
| 291 | 0 | if (newState != null) { |
| 292 | 0 | KSNotifier.add(new KSNotification(getMessage("cluStateChangeNotification" + newState), false, 5000)); |
| 293 | |
|
| 294 | 0 | statusLabel.setText("Status: " + newState); |
| 295 | |
} else { |
| 296 | 0 | KSNotifier.add(new KSNotification(getMessage("cluStateChangeFailedNotification"), false, 5000)); |
| 297 | |
} |
| 298 | 0 | } |
| 299 | |
}); |
| 300 | 0 | widget.updateCourseActionItems(cluModel); |
| 301 | 0 | widget.setEnabled(true); |
| 302 | 0 | if(widget.isEmpty()) { |
| 303 | 0 | widget.setVisible(false); |
| 304 | |
} |
| 305 | |
else{ |
| 306 | 0 | widget.setVisible(true); |
| 307 | |
} |
| 308 | |
} |
| 309 | |
} |
| 310 | 0 | } |
| 311 | |
|
| 312 | |
public Widget getStatusLabel() { |
| 313 | 0 | statusLabel.setStyleName("courseStatusLabel"); |
| 314 | 0 | return statusLabel; |
| 315 | |
} |
| 316 | |
|
| 317 | |
public DataModelDefinition getDefinition(){ |
| 318 | 0 | return definition; |
| 319 | |
} |
| 320 | |
|
| 321 | |
public void setCurrentVersionId(String id) { |
| 322 | 0 | this.currentVersionId = id; |
| 323 | 0 | } |
| 324 | |
|
| 325 | |
public String getCurrentVersionId() { |
| 326 | 0 | return currentVersionId; |
| 327 | |
} |
| 328 | |
|
| 329 | |
public String getVersionIndId() { |
| 330 | 0 | return versionIndId; |
| 331 | |
} |
| 332 | |
|
| 333 | |
public String getMessage(String courseMessageKey) { |
| 334 | 0 | String msg = Application.getApplicationContext().getMessage(MSG_GROUP, courseMessageKey); |
| 335 | 0 | if (msg == null) { |
| 336 | 0 | msg = courseMessageKey; |
| 337 | |
} |
| 338 | 0 | return msg; |
| 339 | |
} |
| 340 | |
|
| 341 | |
|
| 342 | |
@Override |
| 343 | |
public <V extends Enum<?>> void showView(V viewType, Callback<Boolean> onReadyCallback) { |
| 344 | 0 | if(viewType != Views.VERSION_SELECT){ |
| 345 | 0 | workflowVersionInfoSection.setVisible(true); |
| 346 | 0 | this.getHeader().showPrint(true); |
| 347 | |
} |
| 348 | |
else{ |
| 349 | 0 | workflowVersionInfoSection.setVisible(false); |
| 350 | 0 | this.getHeader().showPrint(false); |
| 351 | |
} |
| 352 | 0 | super.showView(viewType, onReadyCallback); |
| 353 | 0 | } |
| 354 | |
|
| 355 | |
|
| 356 | |
|
| 357 | |
public void setCurrentTitle(String currentTitle) { |
| 358 | 0 | this.getHeader().setTitle(currentTitle); |
| 359 | 0 | } |
| 360 | |
} |