Skip to content

Commit

Permalink
Updating the package
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Dec 2, 2016
1 parent de686d7 commit 97ea808
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 53 deletions.
41 changes: 26 additions & 15 deletions resources/assets/js/MediaManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<script>
const config = require('./Config').default;
import eventHub from './shared/EventHub'
import eventHub from './../../../shared/EventHub'
export default {
data () {
Expand All @@ -105,7 +105,8 @@
medias: [],
loading: true,
newDirectory: '',
selected: null
selected: null,
modalOpened: false
}
},
components: {
Expand All @@ -118,42 +119,46 @@
this.getHomeDirectory();
},
created() {
window.addEventListener('keyup', function(e) {
let me = this;
window.addEventListener('keyup', e => {
if (me.modalOpened) return;
switch (e.keyCode) {
case 39: // right
this.selectNextMedia();
me.selectNextMedia();
break;
case 37: // left
this.selectPreviousMedia();
me.selectPreviousMedia();
break;
case 13: // enter
if (this.hasSelectedMedia()) {
this.openMedia(this.selected);
if (me.hasSelectedMedia()) {
me.openMedia(me.selected);
}
break;
case 46: // delete
if (this.hasSelectedMedia()) {
this.openDeleteMediaModal()
if (me.hasSelectedMedia()) {
me.openDeleteMediaModal()
}
break;
case 8: // backspace
if (this.breadcrumbs.length) {
this.breadcrumbs = _.dropRight(this.breadcrumbs, 1);
if (me.breadcrumbs.length) {
me.breadcrumbs = _.dropRight(me.breadcrumbs, 1);
}
break;
// case 27: // escape
// this.resetSelected();
// me.resetSelected();
// break;
default:
// no break
}
}.bind(this), false)
}, false)
},
watch: {
// whenever question changes, this function will run
Expand Down Expand Up @@ -200,8 +205,7 @@
return media.type == 'file';
},
isMediaImage(media) {
if ( ! this.isMediaFile(media))
return false;
if ( ! this.isMediaFile(media)) return false;
return _.indexOf(config.supportedImages, media.mimetype) >= 0;
},
Expand Down Expand Up @@ -266,15 +270,22 @@
openNewFolderModal() {
eventHub.$emit('open-new-folder-modal', {});
this.modalOpened = true;
},
openMediaFolderModal() {
eventHub.$emit('open-rename-media-modal', {});
this.modalOpened = true;
},
openUploadMediaModal() {
eventHub.$emit('open-upload-media-modal', {});
this.modalOpened = true;
},
openDeleteMediaModal() {
eventHub.$emit('open-delete-media-modal', {});
this.modalOpened = true;
},
mediaModalClosed() {
this.modalOpened = false;
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion resources/assets/js/Modals/CreateFolderModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

<script>
const config = require('./../Config').default;
import eventHub from './../shared/EventHub'
import eventHub from './../../../../shared/EventHub'
export default {
props: ['location'],
Expand All @@ -52,6 +53,8 @@
$('div#newFolderModal').modal('hide');
this.$parent.mediaModalClosed();
this.newDirectory = '';
});
}
Expand Down
5 changes: 4 additions & 1 deletion resources/assets/js/Modals/DeleteMediaModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

<script>
const config = require('./../Config').default;
import eventHub from './../shared/EventHub'
import eventHub from './../../../../shared/EventHub'
export default {
props: ['media'],
Expand All @@ -49,6 +50,8 @@
$('div#deleteFolderModal').modal('hide');
this.$parent.mediaModalClosed();
this.newDirectory = '';
});
}
Expand Down
5 changes: 4 additions & 1 deletion resources/assets/js/Modals/RenameMediaModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

<script>
const config = require('./../Config').default;
import eventHub from './../shared/EventHub'
import eventHub from './../../../../shared/EventHub'
export default {
props: ['location', 'media'],
Expand All @@ -53,6 +54,8 @@
this.$parent.refreshDirectory();
$('div#renameFolderModal').modal('hide');
this.$parent.mediaModalClosed();
});
}
}
Expand Down
36 changes: 19 additions & 17 deletions resources/assets/js/Modals/UploadMediaModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<h4 class="modal-title">Upload</h4>
</div>
<div class="modal-body">
<input @change="prepare" type="file" name="media" id="media" class="form-control">
<input @change="prepare" type="file" multiple>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-sm btn-default pull-left" data-dismiss="modal">
Expand All @@ -26,13 +26,14 @@

<script>
const config = require('./../Config').default;
import eventHub from './../shared/EventHub'
import eventHub from './../../../../shared/EventHub'
export default {
props: ['location'],
data () {
return {
medias: null
formData: null
}
},
mounted() {
Expand All @@ -42,27 +43,28 @@
},
methods: {
prepare(e) {
let medias = e.target.files || e.dataTransfer.files;
this.medias = new FormData;
let medias = e.target.files || e.dataTransfer.files;
this.formData = new FormData;
this.formData.append('location', this.location);
// for single file
this.medias.append('media', medias[0]);
// Or for multiple files you can also do
// _.each(files, function(v, k){
// data.append('avatars['+k+']', v);
// });
_.forEach(medias, (media, index) => {
this.formData.append('medias['+index+']', media);
});
},
upload() {
this.$http
.post(config.endpoint + '/upload', {
medias: this.medias
})
.post(config.endpoint + '/upload', this.formData)
.then((response) => {
this.$parent.refreshDirectory();
if (response.data.status == 'success') {
this.$parent.refreshDirectory();
$('div#uploadMediaModal').modal('hide');
$('div#uploadMediaModal').modal('hide');
this.$parent.mediaModalClosed();
this.medias = null;
this.formData = null;
}
});
}
}
Expand Down
1 change: 0 additions & 1 deletion resources/assets/js/Shared/EventHub.js

This file was deleted.

8 changes: 8 additions & 0 deletions resources/views/manager.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
@endsection

@section('content')
<div class="box">
<div class="box-header with-border">
<h2 class="box-title">Media Manager</h2>
</div>
<div class="box-body no-padding">
<media-manager></media-manager>
</div>
</div>
@endsection

@section('modals')
Expand Down
1 change: 0 additions & 1 deletion src/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ public function __construct()
$this->addBreadcrumbRoute('Media', 'media::foundation.index');
}
}

54 changes: 39 additions & 15 deletions src/Http/Controllers/MediasController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,24 @@ public function getAll(Request $request)

public function uploadMedia(Request $request)
{
dd($request->all());
$validator = \Validator::make($request->all(), [
'location' => 'required',
'medias' => 'required|array',
'medias.*' => 'required|file'
]);

if ($validator->fails()) {
return response()->json(['status' => 'error', 'errors' => $validator->messages()]);
}

$location = $request->get('location');

foreach ($request->file('medias') as $media) {
/** @var \Illuminate\Http\UploadedFile $media */
$media->store($location, $this->getDefaultDiskDriver());
}

return response()->json(['status' => 'success']);
}

public function createDirectory(Request $request)
Expand Down Expand Up @@ -132,27 +149,41 @@ public function deleteMedia(Request $request)
{
// TODO: Add validation
$data = $request->all();
$path = trim($data['media']['path'], '/');

$this->disk()->deleteDirectory($path);
if ($data['media']['type'] == 'file') {
$deleted = $this->disk()->delete($data['media']['path']);
}
else {
$path = trim($data['media']['path'], '/');

return response()->json([
'status' => 'success',
]);
$deleted = $this->disk()->deleteDirectory($path);
}

return response()->json(['status' => $deleted ? 'success' : 'error']);
}

/* ------------------------------------------------------------------------------------------------
| Other Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Get the default disk driver.
*
* @return \Illuminate\Filesystem\FilesystemAdapter
*/
private function getDefaultDiskDriver()
{
return config('arcanesoft.media.filesystem.default');
}

/**
* Get the disk adapter.
*
* @return \Illuminate\Filesystem\FilesystemAdapter
*/
protected function disk()
private function disk()
{
return Storage::disk(config('arcanesoft.media.filesystem.default'));
return Storage::disk($this->getDefaultDiskDriver());
}

/**
Expand Down Expand Up @@ -193,11 +224,4 @@ private function getFilesFromLocation($location)
];
}, $disk->files($location));
}

private function isLocalDisk()
{
$driver = config('arcanesoft.media.filesystem.default');

return config("arcanesoft.media.filesystem.disks.{$driver}.driver", 'local');
}
}
1 change: 1 addition & 0 deletions src/MediaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private function syncFilesystemConfig()
*/
public function boot()
{
parent::boot();
$this->app->register(Providers\RouteServiceProvider::class);

// Publishes
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RouteServiceProvider extends ServiceProvider
*/
protected function getRouteNamespace()
{
return 'Arcanesoft\\Auth\\Http\\Routes';
return 'Arcanesoft\\Media\\Http\\Routes';
}

/**
Expand Down

0 comments on commit 97ea808

Please sign in to comment.