forked from learningequality/kolibri
-
Notifications
You must be signed in to change notification settings - Fork 0
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 learningequality#12686 from AllanOXDi/metadata-com…
…posable Helper function(s) to manage display of metadata tags in the new cards
- Loading branch information
Showing
3 changed files
with
77 additions
and
4 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
73 changes: 73 additions & 0 deletions
73
packages/kolibri-common/composables/useCoachMetadataTags.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,73 @@ | ||
import { ref } from 'kolibri.lib.vueCompositionApi'; | ||
import { ContentNodeKinds } from 'kolibri.coreVue.vuex.constants'; | ||
import coreStrings from 'kolibri.utils.coreStrings'; | ||
import commonCoreStringsMixin from 'kolibri.coreVue.mixins.commonCoreStrings'; | ||
|
||
export function useCoachMetadataTags(contentNode) { | ||
const tags = ref([]); | ||
|
||
const getCategoryTags = () => { | ||
if (!contentNode.categories) return []; | ||
return contentNode.categories.map(category => | ||
commonCoreStringsMixin.methods.coreString(category), | ||
); | ||
}; | ||
|
||
const getLevelTags = () => { | ||
if (!contentNode.grade_levels) return []; | ||
return contentNode.grade_levels.map(grade_levels => | ||
commonCoreStringsMixin.methods.coreString(grade_levels), | ||
); | ||
}; | ||
|
||
const getLanguageTag = () => { | ||
if (!contentNode.lang) return []; | ||
return contentNode.lang.lang_name; | ||
}; | ||
|
||
const getActivityTag = () => { | ||
if (!contentNode.learning_activities) return []; | ||
|
||
return contentNode.learning_activities.length > 1 | ||
? [coreStrings.$tr('multipleLearningActivities')] | ||
: contentNode.learning_activities.map(activity => | ||
commonCoreStringsMixin.methods.coreString(activity), | ||
); | ||
}; | ||
|
||
const getDurationTag = () => { | ||
if (!contentNode.duration) return []; | ||
return contentNode.duration.map(duration => coreStrings.formatDuration(duration)); | ||
}; | ||
|
||
const getSpecificCategoryTag = () => { | ||
if (!contentNode.categories) return []; | ||
const specificCategories = contentNode.categories.filter( | ||
category => category.split('.').length > 2, | ||
); | ||
return specificCategories.map(category => commonCoreStringsMixin.methods.coreString(category)); | ||
}; | ||
|
||
if ( | ||
contentNode.kind === ContentNodeKinds.CHANNEL || | ||
contentNode.kind === ContentNodeKinds.TOPIC | ||
) { | ||
tags.value = [ | ||
...getCategoryTags().slice(0, 3), | ||
...getLevelTags().slice(0, 3), | ||
...getLanguageTag(), | ||
]; | ||
} else { | ||
tags.value = [ | ||
...getActivityTag(), | ||
...getDurationTag(), | ||
...getLevelTags(), | ||
...getSpecificCategoryTag(), | ||
...getLanguageTag(), | ||
].slice(0, 3); | ||
} | ||
|
||
return { | ||
tags, | ||
}; | ||
} |