-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from schulcloud/174-implement-paging-functiona…
…lity-for-administration-tables Use paging for administration tables
- Loading branch information
Showing
25 changed files
with
1,116 additions
and
288 deletions.
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
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 |
---|---|---|
@@ -1,42 +1,69 @@ | ||
import { Permissions, Server } from '../../core/helpers/'; | ||
|
||
const schoolService = Server.service('/schools'); | ||
const classService = Server.service('/classes'); | ||
const courseService = Server.service('/courses'); | ||
const userService = Server.service('/users'); | ||
const classService = Server.service('/classes'); | ||
|
||
const indexArrayByKey = (array, key) => { | ||
const result = {}; | ||
array.forEach((obj) => { | ||
result[obj[key]] = obj; | ||
}); | ||
return result; | ||
}; | ||
|
||
export default { | ||
updateSchool: (data) => { | ||
if(data._id) return schoolService.patch(data._id, data); | ||
|
||
return schoolService.create(data); | ||
loadContent: (serviceName, query) => { | ||
const service = Server.service(serviceName); | ||
return service.find({query}) | ||
.then(result => { | ||
return Promise.resolve({ | ||
records: indexArrayByKey(result.data, '_id'), | ||
pagination: {total: result.total, skip: result.skip} | ||
}); | ||
}); | ||
}, | ||
|
||
|
||
updateCourse: (data) => { | ||
if(data._id) return courseService.patch(data._id, data); | ||
|
||
return courseService.create(data); | ||
updateRecord: (serviceName, data) => { | ||
const service = Server.service(serviceName); | ||
if(data._id) return service.patch(data._id, data); | ||
return service.create(data); | ||
}, | ||
|
||
removeCourse: (data) => { | ||
return courseService.remove(data._id); | ||
removeRecord: (serviceName, data) => { | ||
const id = data._id; | ||
if(!id) throw new Error("_id not set!"); | ||
const service = Server.service(serviceName); | ||
return service.remove(id); | ||
}, | ||
|
||
|
||
updateClass: (data) => { | ||
if(data._id) return classService.patch(data._id, data); | ||
|
||
return classService.create(data); | ||
populateFields: (serviceName, _id, fields) => { | ||
const service = Server.service(serviceName); | ||
return service.find({query: { | ||
_id, | ||
$populate: fields | ||
}}) | ||
.then(result => Promise.resolve(result.data[0])); | ||
}, | ||
|
||
removeClass: (data) => { | ||
return classService.remove(data._id); | ||
_loadTeachers: (schoolId) => { | ||
return userService.find({ | ||
query: { | ||
schoolId, | ||
roles: ['teacher'], | ||
$limit: 1000 | ||
} | ||
}) | ||
.then(result => Promise.resolve(result.data)); | ||
}, | ||
|
||
updateUser: (data) => { | ||
if(data._id) return userService.patch(data._id, data); | ||
|
||
return userService.create(data); | ||
_loadClasses: (schoolId) => { | ||
return classService.find({ | ||
query: { | ||
schoolId, | ||
$limit: 1000 | ||
} | ||
}) | ||
.then(result => Promise.resolve(result.data)); | ||
} | ||
}; |
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
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
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
Oops, something went wrong.