-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StudentSupportForm: Adding ui tracking to state #1450
- Loading branch information
Showing
4 changed files
with
354 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
app/instructionalSupport/studentSupportCallForm/services/studentActions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
instructionalSupportApp.service('supportStaffFormActionCreators', function ($rootScope, $window, studentService, studentReducers) { | ||
return { | ||
getInitialState: function (workgroupId, year, termShortCode) { | ||
studentService.getInitialState(workgroupId, year, termShortCode).then(function (payload) { | ||
var action = { | ||
type: INIT_STATE, | ||
payload: payload, | ||
year: year | ||
}; | ||
studentReducers.reduce(action); | ||
}, function (err) { | ||
$rootScope.$emit('toast', { message: "Could not load support staff form initial state.", type: "ERROR" }); | ||
}); | ||
}, | ||
addStudentPreference: function (preference) { | ||
studentService.addStudentPreference(preference).then(function (payload) { | ||
$rootScope.$emit('toast', { message: "Added Preference", type: "SUCCESS" }); | ||
var action = { | ||
type: ADD_STUDENT_PREFERENCE, | ||
payload: payload | ||
}; | ||
studentReducers.reduce(action); | ||
}, function (err) { | ||
$rootScope.$emit('toast', { message: "Could not add preference.", type: "ERROR" }); | ||
}); | ||
}, | ||
updateSupportCallResponse: function (supportCallResponse) { | ||
studentService.updateSupportCallResponse(supportCallResponse).then(function (payload) { | ||
$rootScope.$emit('toast', { message: "Updated preferences", type: "SUCCESS" }); | ||
var action = { | ||
type: UPDATE_SUPPORT_CALL_RESPONSE, | ||
payload: payload | ||
}; | ||
studentReducers.reduce(action); | ||
}, function (err) { | ||
$rootScope.$emit('toast', { message: "Could not update preferences.", type: "ERROR" }); | ||
}); | ||
}, | ||
deleteStudentPreference: function (preference) { | ||
studentService.deleteStudentPreference(preference.id).then(function (payload) { | ||
$rootScope.$emit('toast', { message: "Removed Preference", type: "SUCCESS" }); | ||
var action = { | ||
type: DELETE_STUDENT_PREFERENCE, | ||
payload: preference | ||
}; | ||
studentReducers.reduce(action); | ||
}, function (err) { | ||
$rootScope.$emit('toast', { message: "Could not remove preference.", type: "ERROR" }); | ||
}); | ||
}, | ||
submitPreferences: function (supportCallResponse, workgroupId, year) { | ||
studentService.updateSupportCallResponse(supportCallResponse).then(function (payload) { | ||
$rootScope.$emit('toast', { message: "Updated preferences", type: "SUCCESS" }); | ||
var studentSummaryUrl = "/summary/" + workgroupId + "/" + year + "?mode=instructionalSupport"; | ||
$window.location.href = studentSummaryUrl; | ||
}, function (err) { | ||
$rootScope.$emit('toast', { message: "Could not update preferences.", type: "ERROR" }); | ||
}); | ||
}, | ||
updatePreferencesOrder: function (preferenceIds, scheduleId, termCode) { | ||
studentService.updatePreferencesOrder(preferenceIds, scheduleId, termCode).then(function (payload) { | ||
$rootScope.$emit('toast', { message: "Updated preferences", type: "SUCCESS" }); | ||
var action = { | ||
type: UPDATE_PREFERENCES_ORDER, | ||
payload: payload | ||
}; | ||
studentReducers.reduce(action); | ||
}, function (err) { | ||
$rootScope.$emit('toast', { message: "Could not update preference order.", type: "ERROR" }); | ||
}); | ||
}, | ||
updatePreference: function (scheduleId, preference) { | ||
studentService.updatePreference(scheduleId, preference).then(function (payload) { | ||
$rootScope.$emit('toast', { message: "Updated preference comments", type: "SUCCESS" }); | ||
var action = { | ||
type: UPDATE_PREFERENCE, | ||
payload: payload | ||
}; | ||
studentReducers.reduce(action); | ||
}, function (err) { | ||
$rootScope.$emit('toast', { message: "Could not update preference comments.", type: "ERROR" }); | ||
}); | ||
}, | ||
pretendToastMessage: function () { | ||
$rootScope.$emit('toast', { message: "Updated preferences", type: "SUCCESS" }); | ||
}, | ||
openPreferenceCommentsModal: function() { | ||
studentReducers.reduce({ | ||
type: OPEN_PREFERENCE_COMMENT_MODAL | ||
}); | ||
}, | ||
closePreferenceCommentsModal: function() { | ||
studentReducers.reduce({ | ||
type: CLOSE_PREFERENCE_COMMENT_MODAL | ||
}); | ||
} | ||
}; | ||
}); |
173 changes: 173 additions & 0 deletions
173
app/instructionalSupport/studentSupportCallForm/services/studentReducers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
instructionalSupportApp.service('studentReducers', function ($rootScope, $log, supportStaffFormSelectors) { | ||
return { | ||
_state: {}, | ||
_sectionGroupReducers: function (action, sectionGroups) { | ||
switch (action.type) { | ||
case INIT_STATE: | ||
sectionGroups = { | ||
ids: [], | ||
list: {} | ||
}; | ||
action.payload.sectionGroups.forEach( function(sectionGroup) { | ||
sectionGroups.ids.push(sectionGroup.id); | ||
sectionGroups.list[sectionGroup.id] = sectionGroup; | ||
}); | ||
return sectionGroups; | ||
default: | ||
return sectionGroups; | ||
} | ||
}, | ||
_courseReducers: function (action, courses) { | ||
switch (action.type) { | ||
case INIT_STATE: | ||
courses = { | ||
ids: [], | ||
list: [] | ||
}; | ||
action.payload.courses.forEach( function(course) { | ||
courses.ids.push(course.id); | ||
courses.list[course.id] = course; | ||
}); | ||
return courses; | ||
default: | ||
return courses; | ||
} | ||
}, | ||
_preferenceReducers: function (action, preferences) { | ||
switch (action.type) { | ||
case INIT_STATE: | ||
preferences = { | ||
ids: [], | ||
list: [] | ||
}; | ||
action.payload.studentSupportPreferences.forEach( function(preference) { | ||
preferences.ids.push(preference.id); | ||
preferences.list[preference.id] = preference; | ||
}); | ||
return preferences; | ||
case UPDATE_PREFERENCES_ORDER: | ||
for (var i = 0; i < action.payload.length; i++) { | ||
var preferenceId = action.payload[i]; | ||
var priority = i + 1; | ||
preferences.list[preferenceId].priority = priority; | ||
} | ||
return preferences; | ||
case ADD_STUDENT_PREFERENCE: | ||
var preference = action.payload; | ||
preferences.ids.push(preference.id); | ||
preferences.list[preference.id] = preference; | ||
return preferences; | ||
case DELETE_STUDENT_PREFERENCE: | ||
var preference = action.payload; | ||
var index = preferences.ids.indexOf(preference.id); | ||
preferences.ids.splice(index, 1); | ||
var priority = preference.priority; | ||
preferences.ids.forEach(function(slotPreferenceId) { | ||
var slotPreference = preferences.list[slotPreferenceId]; | ||
if (slotPreference.priority > priority) { | ||
slotPreference.priority--; | ||
} | ||
}); | ||
return preferences; | ||
default: | ||
return preferences; | ||
} | ||
}, | ||
_supportAssignmentReducers: function (action, supportAssignments) { | ||
switch (action.type) { | ||
case INIT_STATE: | ||
supportAssignments = { | ||
ids: [], | ||
list: [] | ||
}; | ||
action.payload.supportAssignments.forEach( function(supportAssignment) { | ||
supportAssignments.ids.push(supportAssignment.id); | ||
supportAssignments.list[supportAssignment.id] = supportAssignment; | ||
}); | ||
return supportAssignments; | ||
default: | ||
return supportAssignments; | ||
} | ||
}, | ||
_miscReducers: function (action, misc) { | ||
switch (action.type) { | ||
case INIT_STATE: | ||
misc = {}; | ||
misc.scheduleId = action.payload.scheduleId; | ||
misc.supportStaffId = action.payload.supportStaffId; | ||
return misc; | ||
default: | ||
return misc; | ||
} | ||
}, | ||
_uiReducers: function (action, ui) { | ||
switch (action.type) { | ||
case INIT_STATE: | ||
ui = { | ||
isPreferenceCommentModalOpen: false | ||
}; | ||
|
||
case OPEN_PREFERENCE_COMMENT_MODAL: | ||
ui.isPreferenceCommentModalOpen = true; | ||
return ui; | ||
case CLOSE_PREFERENCE_COMMENT_MODAL: | ||
ui.isPreferenceCommentModalOpen = false; | ||
return ui; | ||
default: | ||
return ui; | ||
} | ||
}, | ||
_supportCallResponseReducers: function (action, supportCallResponse) { | ||
switch (action.type) { | ||
case INIT_STATE: | ||
supportCallResponse = action.payload.studentSupportCallResponse; | ||
if (!supportCallResponse) { | ||
return null; | ||
} | ||
supportCallResponse.dueDateDescription = millisecondsToDate(supportCallResponse.dueDate); | ||
return supportCallResponse; | ||
case UPDATE_SUPPORT_CALL_RESPONSE: | ||
supportCallResponse = action.payload; | ||
supportCallResponse.dueDateDescription = millisecondsToDate(supportCallResponse.dueDate); | ||
return supportCallResponse; | ||
default: | ||
return supportCallResponse; | ||
} | ||
}, | ||
reduce: function (action) { | ||
newState = {}; | ||
newState.courses = scope._courseReducers(action, scope._state.courses); | ||
newState.sectionGroups = scope._sectionGroupReducers(action, scope._state.sectionGroups); | ||
newState.supportAssignments = scope._supportAssignmentReducers(action, scope._state.supportAssignments); | ||
newState.misc = scope._miscReducers(action, scope._state.misc); | ||
newState.preferences = scope._preferenceReducers(action, scope._state.preferences); | ||
newState.supportCallResponse = scope._supportCallResponseReducers(action, scope._state.supportCallResponse); | ||
newState.ui = scope._uiReducers(action, scope._state.ui); | ||
|
||
scope._state = newState; | ||
|
||
// Build new 'page state' | ||
// This is the 'view friendly' version of the store | ||
newPageState = {}; | ||
newPageState.supportCallResponse = angular.copy(scope._state.supportCallResponse); | ||
newPageState.misc = angular.copy(scope._state.misc); | ||
newPageState.supportAssignments = angular.copy(scope._state.supportAssignments); | ||
|
||
newPageState.preferences = supportStaffFormSelectors.generatePreferences( | ||
scope._state.preferences, | ||
scope._state.courses, | ||
scope._state.sectionGroups | ||
); | ||
|
||
newPageState.potentialPreferences = supportStaffFormSelectors.generatePotentialPreferences( | ||
scope._state.supportAssignments, | ||
scope._state.courses, | ||
scope._state.sectionGroups, | ||
scope._state.preferences, | ||
scope._state.supportCallResponse | ||
); | ||
|
||
$rootScope.$emit('studentStateChanged', newPageState); | ||
} | ||
}; | ||
}); |
77 changes: 77 additions & 0 deletions
77
app/instructionalSupport/studentSupportCallForm/services/studentService.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
instructionalSupportApp.factory("studentService", this.studentService = function($http, $q, $window) { | ||
return { | ||
getInitialState: function(workgroupId, year, termShortCode) { | ||
var deferred = $q.defer(); | ||
|
||
$http.get(serverRoot + "/api/instructionalSupportStudentFormView/workgroups/" + workgroupId + "/years/" + year + "/termCode/" + termShortCode, { withCredentials: true }) | ||
.success(function(assignmentView) { | ||
deferred.resolve(assignmentView); | ||
}) | ||
.error(function() { | ||
deferred.reject(); | ||
}); | ||
|
||
return deferred.promise; | ||
}, | ||
addStudentPreference: function(preference) { | ||
var deferred = $q.defer(); | ||
$http.post(serverRoot + "/api/instructionalSupportStudentFormView/sectionGroups/" + preference.sectionGroupId + "/preferenceType/" + preference.appointmentType + "/percentage/" + preference.appointmentPercentage, { withCredentials: true }) | ||
.success(function(assignmentView) { | ||
deferred.resolve(assignmentView); | ||
}) | ||
.error(function() { | ||
deferred.reject(); | ||
}); | ||
|
||
return deferred.promise; | ||
}, | ||
updateSupportCallResponse: function(supportCallResponse) { | ||
var deferred = $q.defer(); | ||
$http.put(serverRoot + "/api/instructionalSupportStudentFormView/studentSupportCallResponses/" + supportCallResponse.id, supportCallResponse, { withCredentials: true }) | ||
.success(function(assignmentView) { | ||
deferred.resolve(assignmentView); | ||
}) | ||
.error(function() { | ||
deferred.reject(); | ||
}); | ||
|
||
return deferred.promise; | ||
}, | ||
updatePreferencesOrder: function(preferenceIds, scheduleId, termCode) { | ||
var deferred = $q.defer(); | ||
$http.put(serverRoot + "/api/instructionalSupportStudentFormView/schedules/" + scheduleId + "/terms/" + termCode, preferenceIds, { withCredentials: true }) | ||
.success(function(payload) { | ||
deferred.resolve(payload); | ||
}) | ||
.error(function() { | ||
deferred.reject(); | ||
}); | ||
|
||
return deferred.promise; | ||
}, | ||
updatePreference: function(scheduleId, preference) { | ||
var deferred = $q.defer(); | ||
$http.put(serverRoot + "/api/instructionalSupportStudentFormView/schedules/" + scheduleId + "/preferences/" + preference.id, preference, { withCredentials: true }) | ||
.success(function(payload) { | ||
deferred.resolve(payload); | ||
}) | ||
.error(function() { | ||
deferred.reject(); | ||
}); | ||
|
||
return deferred.promise; | ||
}, | ||
deleteStudentPreference: function(preferenceId) { | ||
var deferred = $q.defer(); | ||
$http.delete(serverRoot + "/api/instructionalSupportStudentFormView/studentInstructionalSupportPreferences/" + preferenceId, { withCredentials: true }) | ||
.success(function(payload) { | ||
deferred.resolve(payload); | ||
}) | ||
.error(function() { | ||
deferred.reject(); | ||
}); | ||
|
||
return deferred.promise; | ||
} | ||
}; | ||
}); |