diff --git a/docs/dev/frontend.rst b/docs/dev/frontend.rst index 2de41a15c72..3a76623c5c6 100644 --- a/docs/dev/frontend.rst +++ b/docs/dev/frontend.rst @@ -56,7 +56,7 @@ For example: management/ assets/ src/ - learner-roster.vue # nested-view + user-roster.vue # nested-view vue/index.vue # root view app.js # instantiate mgmt app on client-side test/ diff --git a/docs/dev/user_management.rst b/docs/dev/user_management.rst index cf3479d6cb0..9cbbcee7cf1 100644 --- a/docs/dev/user_management.rst +++ b/docs/dev/user_management.rst @@ -49,7 +49,7 @@ interaction with the selectors and filters. Each item in this list corresponds t * A ``manage`` button which summons a class and group management modal for that student. .. note:: - The roster described here corresponds to ``learner-roster.vue``. + The roster described here corresponds to ``user-roster.vue``. The detail view modal displays learner account data and provides a mechanism to reset a learner's password. @@ -91,9 +91,6 @@ The UI allows the list of learner in the roster to be filtered. This includes: to the classroom selector. * Potentially other filters, for example listing learners in alphabetical or reverse-alphabetical order. -.. note:: - The classroom and group selectors are both instances of ``drop-down.vue``. Space is reserved in ``app-root.vue`` right now for other filters, however they don't correspond to subcomponents. - Miscellaneous widgets ********************* diff --git a/kolibri/auth/test/test_models.py b/kolibri/auth/test/test_models.py index d5726f1d776..faa98bb0261 100644 --- a/kolibri/auth/test/test_models.py +++ b/kolibri/auth/test/test_models.py @@ -385,7 +385,7 @@ def test_membership_str_method(self): self.assertEqual(str(self.learner.membership_set.all()[0]), '"foo"@"Arkham"\'s membership in "Oodles of Fun" (learnergroup)') def test_role_str_method(self): - self.assertEqual(str(self.classroom_coach.role_set.all()[0]), '"bar"@"Arkham"\'s coach role for "Classroom X" (classroom)') + self.assertEqual(str(self.classroom_coach.roles.all()[0]), '"bar"@"Arkham"\'s coach role for "Classroom X" (classroom)') def test_facility_str_method(self): self.assertEqual(str(self.facility), "Arkham") diff --git a/kolibri/plugins/management/assets/src/actions.js b/kolibri/plugins/management/assets/src/actions.js index 4a6eea8f761..d312b69d351 100644 --- a/kolibri/plugins/management/assets/src/actions.js +++ b/kolibri/plugins/management/assets/src/actions.js @@ -14,8 +14,8 @@ function createUser(store, payload, role) { newUserPromise.then((model) => { // assgin role to this new user if the role is not learner if (role === 'learner' || !role) { - // mutation ADD_LEARNERS only take array - store.dispatch('ADD_LEARNERS', [model]); + // mutation ADD_USERS only take array + store.dispatch('ADD_USERS', [model]); } else { const rolePayload = { user: model.id, @@ -26,7 +26,7 @@ function createUser(store, payload, role) { const newRolePromise = RoleModel.save(rolePayload); newRolePromise.then((results) => { FacilityUserModel.fetch({}, true).then(updatedModel => { - store.dispatch('ADD_LEARNERS', [updatedModel]); + store.dispatch('ADD_USERS', [updatedModel]); }); }).catch((error) => { store.dispatch('SET_ERROR', JSON.stringify(error, null, '\t')); @@ -66,7 +66,7 @@ function updateUser(store, id, payload, role) { // force role change because if the role is the only changing attribute // FacilityUserModel.save() will not send request to server. responses.roles = [newRole]; - store.dispatch('UPDATE_LEARNERS', [responses]); + store.dispatch('UPDATE_USERS', [responses]); }) .catch((error) => { store.dispatch('SET_ERROR', JSON.stringify(error, null, '\t')); @@ -89,7 +89,7 @@ function updateUser(store, id, payload, role) { // force role change because if the role is the only changing attribute // FacilityUserModel.save() will not send request to server. responses.roles = [newRole]; - store.dispatch('UPDATE_LEARNERS', [responses]); + store.dispatch('UPDATE_USERS', [responses]); }) .catch((error) => { store.dispatch('SET_ERROR', JSON.stringify(error, null, '\t')); @@ -107,7 +107,7 @@ function updateUser(store, id, payload, role) { // force role change because if the role is the only changing attribute // FacilityUserModel.save() will not send request to server. responses.roles = []; - store.dispatch('UPDATE_LEARNERS', [responses]); + store.dispatch('UPDATE_USERS', [responses]); }) .catch((error) => { store.dispatch('SET_ERROR', JSON.stringify(error, null, '\t')); @@ -117,7 +117,7 @@ function updateUser(store, id, payload, role) { } else { // the role is not changed FacilityUserModel.save(payload).then(responses => { - store.dispatch('UPDATE_LEARNERS', [responses]); + store.dispatch('UPDATE_USERS', [responses]); }) .catch((error) => { store.dispatch('SET_ERROR', JSON.stringify(error, null, '\t')); @@ -137,7 +137,7 @@ function deleteUser(store, id) { const FacilityUserModel = Kolibri.resources.FacilityUserResource.getModel(id); const newUserPromise = FacilityUserModel.delete(id); newUserPromise.then((userId) => { - store.dispatch('DELETE_LEARNERS', [userId]); + store.dispatch('DELETE_USERS', [userId]); }) .catch((error) => { store.dispatch('SET_ERROR', JSON.stringify(error, null, '\t')); @@ -145,23 +145,18 @@ function deleteUser(store, id) { } // An action for setting up the initial state of the app by fetching data from the server -function fetch(store) { +function fetchInitialData(store) { const learnerCollection = FacilityUserResource.getCollection(); const roleCollection = RoleResource.getCollection(); const facilityIdPromise = learnerCollection.getCurrentFacility(); - const learnerPromise = learnerCollection.fetch(); + const userPromise = learnerCollection.fetch(); const rolePromise = roleCollection.fetch(); - const promises = [facilityIdPromise, learnerPromise, rolePromise]; + const promises = [facilityIdPromise, userPromise, rolePromise]; Promise.all(promises).then(responses => { const id = responses[0]; - if (id.constructor === Array) { - // for mvp, we assume only one facility ever existed. - store.dispatch('SET_FACILITY', id[0]); - } else { - store.dispatch('SET_FACILITY', id); - } - const learners = responses[1]; - store.dispatch('ADD_LEARNERS', learners); + store.dispatch('SET_FACILITY', id[0]); // for mvp, we assume only one facility exists + const users = responses[1]; + store.dispatch('ADD_USERS', users); }, rejects => { store.dispatch('SET_ERROR', JSON.stringify(rejects, null, '\t')); @@ -172,5 +167,5 @@ module.exports = { createUser, updateUser, deleteUser, - fetch, + fetchInitialData, }; diff --git a/kolibri/plugins/management/assets/src/app.js b/kolibri/plugins/management/assets/src/app.js index 7147933ede6..b6e723f0e7c 100644 --- a/kolibri/plugins/management/assets/src/app.js +++ b/kolibri/plugins/management/assets/src/app.js @@ -12,11 +12,11 @@ class ManagementModule extends KolibriModule { store: require('./state/store.js').store, vuex: { actions: { - fetch: actions.fetch, + fetchInitialData: actions.fetchInitialData, }, }, }); - this.vm.fetch(); + this.vm.fetchInitialData(); } } diff --git a/kolibri/plugins/management/assets/src/state/getters.js b/kolibri/plugins/management/assets/src/state/getters.js deleted file mode 100644 index 440cd4a1b04..00000000000 --- a/kolibri/plugins/management/assets/src/state/getters.js +++ /dev/null @@ -1,27 +0,0 @@ -function getClassrooms(state) { - return state.classrooms; -} - -function getLearnerGroups(state) { - return state.learnerGroups; -} - -function getLearners(state) { - return state.learners; -} - -function getSelectedClassroomId(state) { - return state.selectedClassroomId; -} - -function getSelectedGroupId(state) { - return state.selectedGroupId; -} - -module.exports = { - getClassrooms, - getLearnerGroups, - getLearners, - getSelectedClassroomId, - getSelectedGroupId, -}; diff --git a/kolibri/plugins/management/assets/src/state/store.js b/kolibri/plugins/management/assets/src/state/store.js index ae0d1fa2360..ca5ca32691b 100644 --- a/kolibri/plugins/management/assets/src/state/store.js +++ b/kolibri/plugins/management/assets/src/state/store.js @@ -2,45 +2,45 @@ const Vuex = require('vuex'); function getInitialState() { return { - facility: 1, - learners: [], + facility: undefined, + users: [], error: '', }; } const mutations = { - ADD_LEARNERS(state, learners) { - learners.forEach(learner => { - state.learners.push({ - id: learner.id, - username: learner.username, - first_name: learner.first_name, - last_name: learner.last_name, - roles: learner.roles, + ADD_USERS(state, users) { + users.forEach(user => { + state.users.push({ + id: user.id, + username: user.username, + first_name: user.first_name, + last_name: user.last_name, + roles: user.roles, }); }); }, - UPDATE_LEARNERS(state, learners) { - learners.forEach(learner => { - state.learners.forEach(existingLearner => { - if (existingLearner.id === learner.id.toString()) { - existingLearner.username = learner.username; - existingLearner.first_name = learner.first_name; - existingLearner.last_name = learner.last_name; - existingLearner.roles = learner.roles; + UPDATE_USERS(state, users) { + users.forEach(user => { + state.users.forEach(existingUser => { + if (existingUser.id === user.id.toString()) { + existingUser.username = user.username; + existingUser.first_name = user.first_name; + existingUser.last_name = user.last_name; + existingUser.roles = user.roles; } }); }); }, - DELETE_LEARNERS(state, ids) { + DELETE_USERS(state, ids) { ids.forEach(id => { - state.learners.forEach((learner, index) => { - if (learner.id === id) { + state.users.forEach((user, index) => { + if (user.id === id) { if (index > -1) { - state.learners.splice(index, 1); + state.users.splice(index, 1); } } }); diff --git a/kolibri/plugins/management/assets/src/vue/drop-down.vue b/kolibri/plugins/management/assets/src/vue/drop-down.vue deleted file mode 100644 index 7d2f3176a7a..00000000000 --- a/kolibri/plugins/management/assets/src/vue/drop-down.vue +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - diff --git a/kolibri/plugins/management/assets/src/vue/index.vue b/kolibri/plugins/management/assets/src/vue/index.vue index 1395d268228..ea4cb3283d2 100644 --- a/kolibri/plugins/management/assets/src/vue/index.vue +++ b/kolibri/plugins/management/assets/src/vue/index.vue @@ -1,7 +1,7 @@ @@ -12,8 +12,7 @@ module.exports = { components: { 'core-base': require('core-base'), - 'drop-down': require('./drop-down.vue'), - 'learner-roster': require('./learner-roster.vue'), + 'user-roster': require('./user-roster.vue'), }, vuex: { actions: require('../actions.js'), diff --git a/kolibri/plugins/management/assets/src/vue/user-create-modal.vue b/kolibri/plugins/management/assets/src/vue/user-create-modal.vue index e0850bcec6b..bdfebbbc159 100644 --- a/kolibri/plugins/management/assets/src/vue/user-create-modal.vue +++ b/kolibri/plugins/management/assets/src/vue/user-create-modal.vue @@ -1,16 +1,16 @@