Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 59 additions & 52 deletions dist/js/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,16 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
});
},
deleteImage: function deleteImage(index) {
axios.delete('/nova-vendor/array-images/delete/' + this.images[index].name);
this.images.splice(index, 1);
this.value = JSON.stringify(this.images);
var image = this.images[index]
var saved_path = image.saved_path
var params = { disk: this.field.disk }

axios.delete('/nova-vendor/array-images/delete/' + encodeURIComponent(saved_path), { params })
.then(() => {
this.images.splice(index, 1)
this.value = JSON.stringify(this.images)
})
.catch(console.warn)
},


Expand Down Expand Up @@ -3275,28 +3282,28 @@ process.umask = function() { return 0; };
/* 76 */
/***/ (function(module, exports) {

module.exports = function(module) {
if(!module.webpackPolyfill) {
module.deprecate = function() {};
module.paths = [];
// module.parent = undefined by default
if(!module.children) module.children = [];
Object.defineProperty(module, "loaded", {
enumerable: true,
get: function() {
return module.l;
}
});
Object.defineProperty(module, "id", {
enumerable: true,
get: function() {
return module.i;
}
});
module.webpackPolyfill = 1;
}
return module;
};
module.exports = function(module) {
if(!module.webpackPolyfill) {
module.deprecate = function() {};
module.paths = [];
// module.parent = undefined by default
if(!module.children) module.children = [];
Object.defineProperty(module, "loaded", {
enumerable: true,
get: function() {
return module.l;
}
});
Object.defineProperty(module, "id", {
enumerable: true,
get: function() {
return module.i;
}
});
module.webpackPolyfill = 1;
}
return module;
};


/***/ }),
Expand Down Expand Up @@ -4471,7 +4478,7 @@ function singularOrPlural(value, suffix) {

/**
* Javascript inflector
*
*
* @author Dida Nurwanda <didanurwanda@gmail.com>
* @since 1.0
*/
Expand Down Expand Up @@ -4570,7 +4577,7 @@ var _Inflector = {
Inflector.pluralize('person') -> 'people'
Inflector.pluralize('octopus') -> 'octopi'
Inflector.pluralize('Hat') -> 'Hats'
Inflector.pluralize('person', 'guys') -> 'guys'
Inflector.pluralize('person', 'guys') -> 'guys'
*/
pluralize: function(str, plural) {
return this.applyRules(
Expand All @@ -4591,7 +4598,7 @@ var _Inflector = {
return this.applyRules(
str,
this.singularRules,
this.uncountableWords,
this.uncountableWords,
singular
);
},
Expand All @@ -4615,7 +4622,7 @@ var _Inflector = {
}
str = str_path.join('::');

// fix
// fix
if (lowFirstLetter === true) {
var first = str.charAt(0).toLowerCase();
var last = str.slice(1);
Expand All @@ -4629,7 +4636,7 @@ var _Inflector = {
Inflector.underscore('MessageProperties') -> 'message_properties'
Inflector.underscore('messageProperties') -> 'message_properties'
*/
underscore: function(str) {
underscore: function(str) {
var str_path = str.split('::');
for (var i = 0; i < str_path.length; i++)
{
Expand Down Expand Up @@ -4735,7 +4742,7 @@ var _Inflector = {
/*
Inflector.foreignKey('MessageBusProperty') -> 'message_bus_property_id'
Inflector.foreignKey('MessageBusProperty', true) -> 'message_bus_propertyid'
*/
*/
foreignKey: function(str, dropIdUbar) {
str = this.underscore(this.demodulize(str)) + ((dropIdUbar) ? ('') : ('_')) + 'id';
return str;
Expand Down Expand Up @@ -10756,27 +10763,27 @@ if (hadRuntime) {
/* 241 */
/***/ (function(module, exports) {

var g;
// This works in non-strict mode
g = (function() {
return this;
})();
try {
// This works if eval is allowed (see CSP)
g = g || Function("return this")() || (1,eval)("this");
} catch(e) {
// This works if the window reference is available
if(typeof window === "object")
g = window;
}
// g can still be undefined, but nothing to do about it...
// We return undefined, instead of nothing here, so it's
// easier to handle this case. if(!global) { ...}
module.exports = g;
var g;

// This works in non-strict mode
g = (function() {
return this;
})();

try {
// This works if eval is allowed (see CSP)
g = g || Function("return this")() || (1,eval)("this");
} catch(e) {
// This works if the window reference is available
if(typeof window === "object")
g = window;
}

// g can still be undefined, but nothing to do about it...
// We return undefined, instead of nothing here, so it's
// easier to handle this case. if(!global) { ...}

module.exports = g;


/***/ })
Expand Down
11 changes: 8 additions & 3 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,14 @@ export default {
},

deleteImage(index) {
axios.delete('/nova-vendor/array-images/delete/'+this.images[index].name);
this.images.splice(index, 1);
this.value = JSON.stringify(this.images);
const { saved_path } = this.images[index]
const params = { disk: this.field.disk }
axios.delete('/nova-vendor/array-images/delete/' + encodeURIComponent(saved_path), { params })
.then(() => {
this.images.splice(index, 1);
this.value = JSON.stringify(this.images);
})
.catch(console.warn)

Choose a reason for hiding this comment

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

why not console.error ?

Copy link
Author

Choose a reason for hiding this comment

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

Because it is not an error in the frontend, and indeed this is not the best way to handle the error, actually it should show a toast or mark the file in some way to let the user know that maybe communication with the backend was temporarily not possible (timed-out), the file could not be found, the path was wrong, etc.

},

/*
Expand Down
3 changes: 2 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

Route::get('/', 'Halimtuhu\ArrayImages\FieldController@index');
Route::post('/upload', 'Halimtuhu\ArrayImages\FieldController@upload');
Route::delete('/delete/{image}', 'Halimtuhu\ArrayImages\FieldController@delete');
Route::delete('/delete/{saved_path}', 'Halimtuhu\ArrayImages\FieldController@delete')
->where('saved_path', '(.*)');
11 changes: 8 additions & 3 deletions src/FieldController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@ public function upload(Request $request)

$data[] = [
'image' => $savedImage,
'saved_path' => $savedImage,
'url' => Storage::disk($disk)->url($savedImage),
];
}

return $data;
}

public function delete($image)
public function delete(Request $request, $saved_path)
{
Storage::delete($image);
$disk = $request->disk ? $request->disk : 'local';

$deleted = Storage::disk($disk)->delete($saved_path);

return "success";
return $deleted === true
? 'success'
: response('not deleted', 404);

Choose a reason for hiding this comment

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

Could be better like that ?

return $deleted === true
            ? response()->noContent()
            : response('Files not found.', 404);

success as a response is not restfull and useless.

Copy link
Author

Choose a reason for hiding this comment

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

I don't know if this should be really a RESTful controller, but this works so I don't know about no use.
Presently, there is not even a real entity being represented here, but I've been thinking that it could be a way to handle #13 having a handler of Preloaded images but not finally attached to the resource, like abandoned editing.

I haven't time to start a new package handling all these issues at once, and was expecting the original writer could attend to the PR's but I'll keep in mind your observation and think the handling of the images in a more restful way.

}
}