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

Media root folder selected by default #6898

Merged
merged 1 commit into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function initializeMediaApplication(displayMediaApplication, mediaApplicationUrl
mediaApp = new Vue({
el: '#mediaApp',
data: {
selectedFolder: root,
selectedFolder: {},
mediaItems: [],
selectedMedias: [],
errors: [],
Expand Down Expand Up @@ -118,6 +118,11 @@ function initializeMediaApplication(displayMediaApplication, mediaApplicationUrl
self.selectedMedias = [];
});

if (!localStorage.getItem('mediaApplicationPrefs')) {
self.selectedFolder = root
return;
}

self.currentPrefs = JSON.parse(localStorage.getItem('mediaApplicationPrefs'));
},
computed: {
Expand Down
326 changes: 166 additions & 160 deletions src/OrchardCore.Modules/OrchardCore.Media/wwwroot/Scripts/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function initializeMediaApplication(displayMediaApplication, mediaApplicationUrl
mediaApp = new Vue({
el: '#mediaApp',
data: {
selectedFolder: _root,
selectedFolder: {},
mediaItems: [],
selectedMedias: [],
errors: [],
Expand Down Expand Up @@ -108,6 +108,12 @@ function initializeMediaApplication(displayMediaApplication, mediaApplicationUrl
self.itemsInPage = itemsInPage;
self.selectedMedias = [];
});

if (!localStorage.getItem('mediaApplicationPrefs')) {
self.selectedFolder = _root;
return;
}

self.currentPrefs = JSON.parse(localStorage.getItem('mediaApplicationPrefs'));
},
computed: {
Expand Down Expand Up @@ -947,165 +953,6 @@ Vue.component('sortIndicator', {
}
}
});
// <upload> component
Vue.component('upload', {
template: '\
<div :class="{ \'upload-warning\' : model.errorMessage }" class="upload m-2 p-2 pt-0"> \
<span v-if="model.errorMessage" v-on:click="dismissWarning()" class="close-warning"><i class="fa fa-times"></i> </span>\
<p class="upload-name" :title="model.errorMessage">{{ model.name }}</p> \
<div> \
<span v-show="!model.errorMessage" :style="{ width: model.percentage + \'%\'}" class="progress-bar"> </span> \
<span v-if="model.errorMessage" class="error-message" :title="model.errorMessage"> Error: {{ model.errorMessage }} </span> \
</div> \
</div> \
',
props: {
model: Object
},
mounted: function mounted() {
var self = this;
$('#fileupload').bind('fileuploadprogress', function (e, data) {
if (data.files[0].name !== self.model.name) {
return;
}

self.model.percentage = parseInt(data.loaded / data.total * 100, 10);
});
$('#fileupload').bind('fileuploaddone', function (e, data) {
if (data.files[0].name !== self.model.name) {
return;
}

if (data.result.files[0].error) {
self.handleFailure(data.files[0].name, data.result.files[0].error);
} else {
bus.$emit('removalRequest', self.model);
}
});
$('#fileupload').bind('fileuploadfail', function (e, data) {
if (data.files[0].name !== self.model.name) {
return;
}

self.handleFailure(data.files[0].name, data.textStatus);
});
},
methods: {
handleFailure: function handleFailure(fileName, message) {
if (fileName !== this.model.name) {
return;
}

this.model.errorMessage = message;
bus.$emit('ErrorOnUpload', this.model);
},
dismissWarning: function dismissWarning() {
bus.$emit('removalRequest', this.model);
}
}
});
// <upload-list> component
Vue.component('uploadList', {
template: '\
<div class="upload-list" v-show="files.length > 0"> \
<div class="header" @click="expanded = !expanded"> \
<span> {{ T.uploads }} </span> \
<span v-show="pendingCount"> (Pending: {{ pendingCount }}) </span> \
<span v-show="errorCount" :class="{ \'text-danger\' : errorCount }"> ( {{ T.errors }}: {{ errorCount }} / <a href="javascript:;" v-on:click.stop="clearErrors" > {{ T.clearErrors }} </a>)</span> \
<div class="toggle-button"> \
<div v-show="expanded"> \
<i class="fa fa-chevron-down"></i> \
</div> \
<div v-show="!expanded"> \
<i class="fa fa-chevron-up"></i> \
</div> \
</div> \
</div> \
<div class="card-body" v-show="expanded"> \
<div class="d-flex flex-wrap"> \
<upload v-for="f in files" :key="f.name" :model="f"></upload> \
</div > \
</div> \
</div> \
',
data: function data() {
return {
files: [],
T: {},
expanded: false,
pendingCount: 0,
errorCount: 0
};
},
created: function created() {
var self = this; // retrieving localized strings from view

self.T.uploads = $('#t-uploads').val();
self.T.errors = $('#t-errors').val();
self.T.clearErrors = $('#t-clear-errors').val();
},
computed: {
fileCount: function fileCount() {
return this.files.length;
}
},
mounted: function mounted() {
var self = this;
$('#fileupload').bind('fileuploadadd', function (e, data) {
if (!data.files) {
return;
}

data.files.forEach(function (newFile) {
var alreadyInList = self.files.some(function (f) {
return f.name == newFile.name;
});

if (!alreadyInList) {
self.files.push({
name: newFile.name,
percentage: 0,
errorMessage: ''
});
} else {
console.error('A file with the same name is already on the queue:' + newFile.name);
}
});
});
bus.$on('removalRequest', function (fileUpload) {
self.files.forEach(function (item, index, array) {
if (item.name == fileUpload.name) {
array.splice(index, 1);
}
});
});
bus.$on('ErrorOnUpload', function (fileUpload) {
self.updateCount();
});
},
methods: {
updateCount: function updateCount() {
this.errorCount = this.files.filter(function (item) {
return item.errorMessage != '';
}).length;
this.pendingCount = this.files.length - this.errorCount;

if (this.files.length < 1) {
this.expanded = false;
}
},
clearErrors: function clearErrors() {
this.files = this.files.filter(function (item) {
return item.errorMessage == '';
});
}
},
watch: {
files: function files() {
this.updateCount();
}
}
});
function initializeAttachedMediaField(el, idOfUploadButton, uploadAction, mediaItemUrl, allowMultiple, tempUploadFolder) {
var target = $(document.getElementById($(el).data('for')));
var initialPaths = target.data("init");
Expand Down Expand Up @@ -1631,6 +1478,165 @@ Vue.component('mediaFieldThumbsContainer', {
}
}
});
// <upload> component
Vue.component('upload', {
template: '\
<div :class="{ \'upload-warning\' : model.errorMessage }" class="upload m-2 p-2 pt-0"> \
<span v-if="model.errorMessage" v-on:click="dismissWarning()" class="close-warning"><i class="fa fa-times"></i> </span>\
<p class="upload-name" :title="model.errorMessage">{{ model.name }}</p> \
<div> \
<span v-show="!model.errorMessage" :style="{ width: model.percentage + \'%\'}" class="progress-bar"> </span> \
<span v-if="model.errorMessage" class="error-message" :title="model.errorMessage"> Error: {{ model.errorMessage }} </span> \
</div> \
</div> \
',
props: {
model: Object
},
mounted: function mounted() {
var self = this;
$('#fileupload').bind('fileuploadprogress', function (e, data) {
if (data.files[0].name !== self.model.name) {
return;
}

self.model.percentage = parseInt(data.loaded / data.total * 100, 10);
});
$('#fileupload').bind('fileuploaddone', function (e, data) {
if (data.files[0].name !== self.model.name) {
return;
}

if (data.result.files[0].error) {
self.handleFailure(data.files[0].name, data.result.files[0].error);
} else {
bus.$emit('removalRequest', self.model);
}
});
$('#fileupload').bind('fileuploadfail', function (e, data) {
if (data.files[0].name !== self.model.name) {
return;
}

self.handleFailure(data.files[0].name, data.textStatus);
});
},
methods: {
handleFailure: function handleFailure(fileName, message) {
if (fileName !== this.model.name) {
return;
}

this.model.errorMessage = message;
bus.$emit('ErrorOnUpload', this.model);
},
dismissWarning: function dismissWarning() {
bus.$emit('removalRequest', this.model);
}
}
});
// <upload-list> component
Vue.component('uploadList', {
template: '\
<div class="upload-list" v-show="files.length > 0"> \
<div class="header" @click="expanded = !expanded"> \
<span> {{ T.uploads }} </span> \
<span v-show="pendingCount"> (Pending: {{ pendingCount }}) </span> \
<span v-show="errorCount" :class="{ \'text-danger\' : errorCount }"> ( {{ T.errors }}: {{ errorCount }} / <a href="javascript:;" v-on:click.stop="clearErrors" > {{ T.clearErrors }} </a>)</span> \
<div class="toggle-button"> \
<div v-show="expanded"> \
<i class="fa fa-chevron-down"></i> \
</div> \
<div v-show="!expanded"> \
<i class="fa fa-chevron-up"></i> \
</div> \
</div> \
</div> \
<div class="card-body" v-show="expanded"> \
<div class="d-flex flex-wrap"> \
<upload v-for="f in files" :key="f.name" :model="f"></upload> \
</div > \
</div> \
</div> \
',
data: function data() {
return {
files: [],
T: {},
expanded: false,
pendingCount: 0,
errorCount: 0
};
},
created: function created() {
var self = this; // retrieving localized strings from view

self.T.uploads = $('#t-uploads').val();
self.T.errors = $('#t-errors').val();
self.T.clearErrors = $('#t-clear-errors').val();
},
computed: {
fileCount: function fileCount() {
return this.files.length;
}
},
mounted: function mounted() {
var self = this;
$('#fileupload').bind('fileuploadadd', function (e, data) {
if (!data.files) {
return;
}

data.files.forEach(function (newFile) {
var alreadyInList = self.files.some(function (f) {
return f.name == newFile.name;
});

if (!alreadyInList) {
self.files.push({
name: newFile.name,
percentage: 0,
errorMessage: ''
});
} else {
console.error('A file with the same name is already on the queue:' + newFile.name);
}
});
});
bus.$on('removalRequest', function (fileUpload) {
self.files.forEach(function (item, index, array) {
if (item.name == fileUpload.name) {
array.splice(index, 1);
}
});
});
bus.$on('ErrorOnUpload', function (fileUpload) {
self.updateCount();
});
},
methods: {
updateCount: function updateCount() {
this.errorCount = this.files.filter(function (item) {
return item.errorMessage != '';
}).length;
this.pendingCount = this.files.length - this.errorCount;

if (this.files.length < 1) {
this.expanded = false;
}
},
clearErrors: function clearErrors() {
this.files = this.files.filter(function (item) {
return item.errorMessage == '';
});
}
},
watch: {
files: function files() {
this.updateCount();
}
}
});
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

/*
Expand Down

Large diffs are not rendered by default.