-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adapt-contrib-resources: add contentObject specific resources #84
Comments
I had to implement this on a project recently, did it as a new extension (adapt-pageSpecificResources) that extended the behaviour of the core resources extension - the below should still be mostly useful to whoever picks this up function setupPageSpecificResources(resourcesData) {
var resourcesModel = new Backbone.Model(resourcesData);
var resourcesCollection = new Backbone.Collection(resourcesModel.get('_resourcesItems'));
/**
* Return the list of resources. If the resources are opened from the main menu, return the entire list
* If opened from a page, only return resources associated with that page or resources that have no page
* association defined.
* @return Backbone.Collection
*/
function getResourcesCollection() {
if (Adapt.location._currentLocation === 'course') {
return resourcesCollection;
}
var filteredResources = resourcesCollection.filter(function(resource) {
var showOnPages = resource.get('_showOnPages');
if (!showOnPages || showOnPages.length === 0) return true;
return (showOnPages.indexOf(Adapt.location._currentId) > -1);
});
return new Backbone.Collection(filteredResources);
}
Adapt.on('pageSpecificResources:showResources', function() {
Adapt.drawer.triggerCustomView(new ResourcesView({
model: resourcesModel,
collection: getResourcesCollection()
}).$el);
});
} |
Sample JSON: {
"_type": "media",
"title": "Global resource",
"description": "A YouTube video",
"_link": "https://youtu.be/mDa42EkgO1A",
"_forceDownload": false,
"_showOnPages": []
},
{
"_type": "link",
"title": "Page 1 Resource 1",
"description": "Kineo Website",
"_link": "https://www.kineo.com",
"_forceDownload": false,
"_showOnPages": [
"5d7101e56169ab34ad379af6"
]
},
{
"_type": "link",
"title": "Page 1 Resource 2",
"description": "Adapt website",
"_link": "https://www.adaptlearning.org",
"_forceDownload": false,
"_showOnPages": [
"5d7101e56169ab34ad379af6"
]
},
{
"_type": "link",
"title": "Page 1, 2 & 3 Resource",
"description": "Adapt YouTube Channel",
"_link": "https://www.youtube.com/channel/UCW8SlSFuCc--B66Gf9fAEcQ",
"_forceDownload": false,
"_showOnPages": [
"5d70fa886169ab34ad3799e3",
"5d70fa886169ab34ad3799e4",
"5d70fa886169ab34ad3799e6"
]
} |
Be good if you can still access the global resources but somehow highlight the content specific resources - just a thought otherwise it may be confusing to the user |
🎉 This issue has been resolved in version 5.3.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
# [5.1.0](v5.0.0...v5.1.0) (2023-07-10) ### Fix * _globals schema nesting (adaptlearning#102) ([6343b0d](6343b0d)), closes [adaptlearning#102](https://github.com/redwoodperforms/adapt-contrib-resources/issues/102) * Add custom types to readme, change 'category' references to 'type' for consistency (fixes adaptlearning#108) ([bbf57a8](bbf57a8)), closes [adaptlearning#108](https://github.com/redwoodperforms/adapt-contrib-resources/issues/108) * Added gitignore for release automation (adaptlearning#81) ([7c6694c](7c6694c)), closes [adaptlearning#81](https://github.com/redwoodperforms/adapt-contrib-resources/issues/81) * Added release automation (adaptlearning#80) ([e9b6923](e9b6923)), closes [adaptlearning#80](https://github.com/redwoodperforms/adapt-contrib-resources/issues/80) * Allow custom types (fixes adaptlearning#103) (adaptlearning#104) ([bfaef6e](bfaef6e)), closes [adaptlearning#103](https://github.com/redwoodperforms/adapt-contrib-resources/issues/103) [adaptlearning#104](https://github.com/redwoodperforms/adapt-contrib-resources/issues/104) * Bump http-cache-semantics from 4.1.0 to 4.1.1 (adaptlearning#95) ([5ae1de4](5ae1de4)), closes [adaptlearning#95](https://github.com/redwoodperforms/adapt-contrib-resources/issues/95) * Convert template to JSX (fixes adaptlearning#89) (adaptlearning#90) ([e4e426e](e4e426e)), closes [adaptlearning#89](https://github.com/redwoodperforms/adapt-contrib-resources/issues/89) [adaptlearning#90](https://github.com/redwoodperforms/adapt-contrib-resources/issues/90) * Header template does not work (fixes adaptlearning#99) (adaptlearning#100) ([55fae85](55fae85)), closes [adaptlearning#99](https://github.com/redwoodperforms/adapt-contrib-resources/issues/99) [adaptlearning#100](https://github.com/redwoodperforms/adapt-contrib-resources/issues/100) * Labels for resources items are unnecessarily verbose ([6b51bbc](6b51bbc)) * Remove required title from contentobject schema (adaptlearning#98) ([6e27c74](6e27c74)), closes [adaptlearning#98](https://github.com/redwoodperforms/adapt-contrib-resources/issues/98) * Remove unnecessary 'this' from currentTarget, remove component__inner class (fixes adaptlearning#91) ([835befc](835befc)), closes [adaptlearning#91](https://github.com/redwoodperforms/adapt-contrib-resources/issues/91) * Semantic release action package versions ([e7d02d4](e7d02d4)) * Typo in template ([d90bd43](d90bd43)) * Update schema $anchor to reference resources (fixes adaptlearning#87) ([930034f](930034f)), closes [adaptlearning#87](https://github.com/redwoodperforms/adapt-contrib-resources/issues/87) * Version numbers removed from Readme files ([292dd99](292dd99)) ### New * Add click event trigger (solves: adaptlearning#106) (adaptlearning#107) ([0d27f68](0d27f68)), closes [adaptlearning#106](https://github.com/redwoodperforms/adapt-contrib-resources/issues/106) [adaptlearning#107](https://github.com/redwoodperforms/adapt-contrib-resources/issues/107) * Added contentObject specific resources (fixes adaptlearning#84) (adaptlearning#85) ([4df42fd](4df42fd)), closes [adaptlearning#84](https://github.com/redwoodperforms/adapt-contrib-resources/issues/84) [adaptlearning#85](https://github.com/redwoodperforms/adapt-contrib-resources/issues/85) * Issue and pr project addition automation (refs adaptlearning/adapt_framework#3315) (adaptlearning#79) ([3657367](3657367)), closes [adaptlearning#79](https://github.com/redwoodperforms/adapt-contrib-resources/issues/79) ### Update * Add missing aria attribution for tabs (adaptlearning#78) ([f3e3e1b](f3e3e1b)), closes [adaptlearning#78](https://github.com/redwoodperforms/adapt-contrib-resources/issues/78) ### Upgrade * Bump yaml and semantic-release (adaptlearning#105) ([28b3873](28b3873)), closes [adaptlearning#105](https://github.com/redwoodperforms/adapt-contrib-resources/issues/105)
Subject of the issue
Currently resources are global, it would be nice to be able to add contentObject specific resources.
Please +1 if you agree that this would be a nice feature.
The text was updated successfully, but these errors were encountered: