Skip to content
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

Extract metadata for ims scorm cp #4258

Open
wants to merge 4 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
class="mb-2 ml-1 mt-0 px-3 py-2"
:label="$tr('selectAllLabel')"
/>
<EditListItem
v-for="nodeId in nodeIds"
:key="nodeId"
<EditListItems
v-model="selected"
:nodeId="nodeId"
:nodeId="parentId"
:nodes="nodes"
:nodeIds="nodeIds"
@input="trackSelect"
@removed="handleRemoved"
/>
Expand All @@ -22,13 +22,14 @@

<script>

import EditListItem from './EditListItem';
import { mapGetters } from 'vuex';
import EditListItems from './EditListItems';
import Checkbox from 'shared/views/form/Checkbox';

export default {
name: 'EditList',
components: {
EditListItem,
EditListItems,
Checkbox,
},
props: {
Expand All @@ -40,8 +41,14 @@
type: Array,
default: () => [],
},
parentId: {
type: String,
require: true,
default: null,
},
},
computed: {
...mapGetters('contentNode', ['getContentNode']),
selected: {
get() {
return this.value;
Expand All @@ -63,11 +70,34 @@
}
},
},
nodes() {
const nodes = {};
this.nodeIds.forEach(nodeId => {
const parentId = this.getContentNode(nodeId).parent;
nodes[`${nodeId}`] = this.nodeIds.includes(parentId) ? parentId : null;
});
return nodes;
},
},
methods: {
...mapGetters('contentNode', ['deleteContentNode']),
getChildren(parent) {
const childrens = [];
Object.keys(this.nodes).forEach(nodeId => {
if (this.nodes[nodeId] === parent) {
childrens.push(...this.getChildren(nodeId));
childrens.push(nodeId);
}
});
return childrens;
},
handleRemoved(nodeId) {
const nodeIds = this.$route.params.detailNodeIds.split(',').filter(id => id !== nodeId);

const removedNodes = this.getChildren(nodeId);
removedNodes.push(nodeId);
removedNodes.forEach(nodeId => this.deleteContentNode(nodeId));
const nodeIds = this.$route.params.detailNodeIds
.split(',')
.filter(id => !removedNodes.includes(id));
this.$router.push({
name: this.$route.name,
params: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

<script>

import { mapActions, mapGetters } from 'vuex';
import { mapGetters } from 'vuex';
import { RouteNames } from '../../constants';
import { fileSizeMixin, fileStatusMixin } from 'shared/mixins';
import ContentNodeIcon from 'shared/views/ContentNodeIcon';
Expand Down Expand Up @@ -166,11 +166,8 @@
},
},
methods: {
...mapActions('contentNode', ['deleteContentNode']),
removeNode() {
this.deleteContentNode(this.nodeId).then(() => {
this.$emit('removed', this.nodeId);
});
this.$emit('removed', this.nodeId);
},
},
$trs: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<template>

<VList two-line class="pl-3">
<EditListItem
:key="nodeId"
v-model="selected"
:nodeId="nodeId"
@input="trackSelect"
@removed="handleRemoved"
/>
<div v-if="getChildren !== undefined && getChildren.length">
<EditListItems
v-for="childId in getChildren"
:key="childId"
v-model="selected"
:nodeId="childId"
:nodes="nodes"
:nodeIds="nodeIds"
@input="trackSelect"
@removed="handleRemoved"
/>
</div>
</VList>

</template>

<script>

import EditListItem from './EditListItem';

export default {
name: 'EditListItems',
components: {
EditListItem,
},
props: {
value: {
type: Array,
default: () => [],
},
nodeIds: {
type: Array,
default: () => [],
},
nodeId: {
type: String,
require: true,
default: null,
},
nodes: {
type: Object,
default: () => {},
},
},
computed: {
selected: {
get() {
return this.value;
},
set(items) {
this.$emit('input', items);
},
},
getChildren() {
const childrens = [];
Object.keys(this.nodes).forEach(nodeId => {
if (this.nodes[nodeId] === this.nodeId) {
childrens.push(nodeId);
}
});
return childrens;
},
},
methods: {
handleRemoved(nodeId) {
this.$emit('removed', nodeId);
},
trackSelect(value) {
this.$emit('input', value);
},
},
};

</script>

<style lang="less" scoped>

.v-divider {
margin-top: 0;
}

</style>
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
<EditList
v-model="selected"
:nodeIds="nodeIds"
@input="enableValidation(nodeIds);"
:parentId="nodeIds[0]"
@input="enableValidation(nodeIds)"
/>
</div>
</FileDropzone>
Expand Down Expand Up @@ -190,13 +191,14 @@
import ResizableNavigationDrawer from 'shared/views/ResizableNavigationDrawer';
import Uploader from 'shared/views/files/Uploader';
import LoadingText from 'shared/views/LoadingText';
import FormatPresets from 'shared/leUtils/FormatPresets';
import FormatPresets, { FormatPresetsList } from 'shared/leUtils/FormatPresets';
import OfflineText from 'shared/views/OfflineText';
import ToolBar from 'shared/views/ToolBar';
import BottomBar from 'shared/views/BottomBar';
import FileDropzone from 'shared/views/files/FileDropzone';
import { isNodeComplete } from 'shared/utils/validation';
import { DELAYED_VALIDATION } from 'shared/constants';
import { DELAYED_VALIDATION, fileErrors } from 'shared/constants';
import { File } from 'shared/data/resources';

const CHECK_STORAGE_INTERVAL = 10000;

Expand Down Expand Up @@ -453,7 +455,7 @@
},

/* Creation actions */
createNode(kind, payload = {}) {
createNode(kind, payload = {}, parent = this.$route.params.nodeId) {
this.enableValidation(this.nodeIds);
// Default learning activity on upload
if (
Expand All @@ -466,7 +468,7 @@
}
return this.createContentNode({
kind,
parent: this.$route.params.nodeId,
parent: parent,
channel_id: this.currentChannel.id,
...payload,
}).then(newNodeId => {
Expand Down Expand Up @@ -498,18 +500,67 @@
.slice(0, -1)
.join('.');
}
this.createNode(
FormatPresets.has(file.preset) && FormatPresets.get(file.preset).kind_id,
{ title, ...file.metadata }
).then(newNodeId => {
if (index === 0) {
this.selected = [newNodeId];
}
this.updateFile({
...file,
contentnode: newNodeId,
if (file.metadata.folders === undefined) {
this.createNode(
FormatPresets.has(file.preset) && FormatPresets.get(file.preset).kind_id,
{ title, ...file.metadata }
).then(newNodeId => {
if (index === 0) {
this.selected = [newNodeId];
}
this.updateFile({
...file,
contentnode: newNodeId,
});
});
});
} else if (file.metadata.folders) {
this.createNode('topic', file.metadata).then(newNodeId => {
file.metadata.folders.forEach(folder => {
this.createNode('topic', folder, newNodeId).then(topicNodeId => {
folder.files.forEach(folderFile => {
const extra_fields = {};
extra_fields['options'] = { entry: folderFile.resourceHref };
extra_fields['title'] = folderFile.title;
let file_kind = null;
FormatPresetsList.forEach(p => {
if (p.id === file.metadata.preset) {
file_kind = p.kind_id;
}
});

this.createNode(file_kind, extra_fields, topicNodeId).then(resourceNodeId => {
return File.uploadUrl({
checksum: file.checksum,
size: file.file_size,
name: file.original_filename,
file_format: file.file_format,
preset: file.metadata.preset,
}).then(data => {
const fileObject = {
...data.file,
loaded: 0,
total: file.size,
};
if (!this.selected.length) {
this.selected = [resourceNodeId];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change this to set this.selected if we haven't already set this.selected to something - so only the first finalized node gets selected.

}
this.updateFile({
...fileObject,
contentnode: resourceNodeId,
}).catch(error => {
let errorType = fileErrors.UPLOAD_FAILED;
if (error.response && error.response.status === 412) {
errorType = fileErrors.NO_STORAGE;
}
return Promise.reject(errorType);
});
});
});
});
});
});
});
}
});
},
updateTitleForPage() {
Expand Down Expand Up @@ -582,4 +633,4 @@
margin-top: -4px !important;
}

</style>
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
},
computed: {
...mapGetters('file', ['getContentNodeFileById', 'getContentNodeFiles']),
...mapGetters('contentNode', ['getContentNode']),
node() {
return this.getContentNode(this.nodeId);
},
file() {
return this.getContentNodeFileById(this.nodeId, this.fileId);
},
Expand Down Expand Up @@ -129,7 +133,9 @@
return this.file.file_format === 'epub';
},
htmlPath() {
return `/zipcontent/${this.file.checksum}.${this.file.file_format}`;
return `/zipcontent/${this.file.checksum}.${this.file.file_format}/${(this.node.options &&
this.node.options.entry) ||
''}`;
},
src() {
return this.file && this.file.url;
Expand Down