Commit c8cde482 authored by Ndame Kital's avatar Ndame Kital
Browse files

fix problèmes webpack à trouver des dependances existntes et quelques refacto

No related merge requests found
Showing with 22 additions and 2794 deletions
+22 -2794
{
"name": "irstea/file-upload-bundle",
"description": "Bundle de gestion de fichiers intégrée à Symfony et Twitter-Bootstrap.",
......@@ -149,6 +150,7 @@
],
"test:install-assets": [
"@test:clear",
"@test:install-theme-assets",
"cd tests/Fixtures && npm install && npm run dev #"
],
"test:install-theme-assets": [
......
const Translator = require('translator');
/*
* Copyright (C) 2015 IRSTEA
* All rights reserved.
*/
(function ($, Translator) {
var formatFileSize = function (size) {
var unit;
if (size > 1000000000) {
size = (size / 1000000000).toFixed(2);
unit = 'Gi';
} else if (size > 1000000) {
size = (size / 1000000).toFixed(2);
unit = 'Mi';
} else if (size > 1000) {
size = (size / 1000).toFixed(2);
unit = 'Ki';
} else {
unit = '';
}
return Translator.trans('file_size(%size%,%unit%)', {size: size, unit: unit}, 'file_upload');
},
formatBitrate = function (rate) {
return formatFileSize(rate) + '/s';
};
$.blueimp.fileupload.prototype._formatFileSize = formatFileSize;
$.blueimp.fileupload.prototype._formatBitrate = formatBitrate;
/** Plugin irsteaFileUpload.
*/
$.fn.irsteaFileUpload = function (options) {
var $this = $(this),
$button = $this.find('.fileinput-button'),
input = $this.find(':file')[0],
$entries = $this.find('.fileinput-entries'),
nextIndex = $entries.find('.fileinput-entry').length,
createUrl = options.createUrl,
uploadPrototype = options.uploadPrototype,
downloadPrototype = options.downloadPrototype,
csrfQuery = '?token=' + options.csrfToken;
delete options.createUrl;
delete options.uploadPrototype;
delete options.downloadPrototype;
delete options.csrfToken;
if (options.acceptFileTypes) {
options.acceptFileTypes = new RegExp('^' + options.acceptFileTypes + '$');
}
var checkValidity = function () {
var counts = {
upload: $entries.find('.template-upload').length,
download: $entries.find('.template-download').length,
error: $entries.find('.alert-danger').length,
},
error = '';
if (counts.upload > 0) {
error = Translator.trans('file_upload.runningUpload', null, 'validators');
} else if (counts.error > 0) {
error = Translator.trans('file_upload.uploadError', null, 'validators');
} else if (options.required && counts.download < 1) {
error = Translator.trans('file_upload.required', null, 'validators');
}
input.setCustomValidity(error);
// console.debug(input, counts, input.validationMessage, input.validity);
},
showError = function (entry, message) {
var $this = $(entry);
if (message) {
$this.find('.error').text(Translator.trans(message));
}
$this.addClass('alert alert-danger');
$this.find('.error').show();
$this.find('.icon')
.removeClass('fa-circle-o-notch fa-spin fa-file-o')
.addClass('fa-exclamation-triangle');
$this.find('.description').remove();
$this.find('.id').remove();
},
updateDisplay = function (event) {
var hasEntry = false;
$entries.find('.fileinput-entry').each(function () {
var data = $(this).data('data');
if (data && data.files.error) {
showError(this, data.files[0].error);
}
hasEntry = true;
});
$button.toggle(options.multiple || !hasEntry);
checkValidity();
};
// Activation
$button.fileupload($.extend(
options,
{
type: 'PUT',
autoUpload: true,
formData: {},
multipart: false,
uploadTemplateId: null,
downloadTemplateId: null,
filesContainer: $this.find('.fileinput-entries'),
dropZone: $this,
i18n: function(key, values, domain) {
var res = Translator.trans(key, values, domain || 'file_upload');
if (res !== key) {
return res;
}
res = Translator.trans('file_upload.'+ key, values, 'validators');
if (res !== 'file_upload.'+ key) {
return res;
}
return Translator.trans(key, values, 'messages');
},
uploadTemplate: function (data) {
var rows = $();
$.each(data.files, function (index, file) {
var row = $(uploadPrototype);
rows = rows.add(row);
row.find('.name').text(file.name);
if (file.error) {
showError(row, file.error);
return;
}
row.find('.size').text(formatFileSize(file.size));
});
return rows;
},
downloadTemplate: function (data) {
var rows = $();
$.each(data.files, function (index, file) {
var row = $(downloadPrototype.replace(/__index__/g, nextIndex++));
rows = rows.add(row);
if (file.error) {
row.find('.name').text(file.name);
showError(row, file.error);
return;
}
row.find('.repr').html(file.repr);
row.find('.delete')
.attr('data-type', file.delete_type)
.attr('data-url', file.delete_url + csrfQuery);
row.find('input.id')
.val(file.id);
});
return rows;
},
submit: function (e, data) {
var $this = $(this),
file = data.files[0];
$.post(
createUrl,
{file: {name: file.name, size: file.size, type: file.type, lastModified: file.lastModified}},
function (response) {
file.icon = response.icon;
data.url = response.put_url + csrfQuery;
data.delete_url = response.delete_url;
data.delete_type = response.delete_type;
data.jqXHR = $this.fileupload('send', data);
}
)
.fail(function (jqXHR, textStatus, errorThrown) {
file.error = textStatus === "error" ? errorThrown : ('Error #' + jqXHR.status);
data.files.error = true;
showError(data.context, file.error);
})
.always(updateDisplay);
return false;
},
progress: function (e, data) {
if (!data.context || e.isDefaultPrevented()) {
return;
}
var percent = data.loaded / data.total * 100,
percentText = percent.toFixed(1);
data.context.each(function () {
var $this = $(data.context);
$this.find('.progress').show();
$this.find('.progress-bar').css('width', percent + '%').attr('aria-valuenow', percentText);
$this.find('.progress-text').show().html(percentText + '% (' + formatBitrate(data.bitrate) + ')');
});
},
getFilesFromResponse: function (data) {
var files = [];
$.each(data.files, function (index, file) {
files.push($.extend(file, data.result.files[index]));
});
return files;
},
}
)).bind({
fileuploadfailed: function (event, data) {
if (data.delete_url) {
$.ajax(data.delete_url + csrfQuery, {type: data.delete_type});
checkValidity();
}
},
fileuploadadded: updateDisplay,
fileuploadfinished: updateDisplay,
fileuploaddestroyed: updateDisplay,
fileuploadprocessalways: updateDisplay
});
if (options.disabled || options.readonly) {
$button.fileupload('disable');
}
updateDisplay();
};
})(jQuery, Translator);
This diff is collapsed.
/*
* jQuery File Upload Processing Plugin
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2012, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* https://opensource.org/licenses/MIT
*/
/* jshint nomen:false */
/* global define, require, window */
;(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// Register as an anonymous AMD module:
define([
'jquery',
'./jquery.fileupload'
], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS:
factory(
require('jquery'),
require('./jquery.fileupload')
);
} else {
// Browser globals:
factory(
window.jQuery
);
}
}(function ($) {
'use strict';
var originalAdd = $.blueimp.fileupload.prototype.options.add;
// The File Upload Processing plugin extends the fileupload widget
// with file processing functionality:
$.widget('blueimp.fileupload', $.blueimp.fileupload, {
options: {
// The list of processing actions:
processQueue: [
/*
{
action: 'log',
type: 'debug'
}
*/
],
add: function (e, data) {
var $this = $(this);
data.process(function () {
return $this.fileupload('process', data);
});
originalAdd.call(this, e, data);
}
},
processActions: {
/*
log: function (data, options) {
console[options.type](
'Processing "' + data.files[data.index].name + '"'
);
}
*/
},
_processFile: function (data, originalData) {
var that = this,
dfd = $.Deferred().resolveWith(that, [data]),
chain = dfd.promise();
this._trigger('process', null, data);
$.each(data.processQueue, function (i, settings) {
var func = function (data) {
if (originalData.errorThrown) {
return $.Deferred()
.rejectWith(that, [originalData]).promise();
}
return that.processActions[settings.action].call(
that,
data,
settings
);
};
chain = chain.then(func, settings.always && func);
});
chain
.done(function () {
that._trigger('processdone', null, data);
that._trigger('processalways', null, data);
})
.fail(function () {
that._trigger('processfail', null, data);
that._trigger('processalways', null, data);
});
return chain;
},
// Replaces the settings of each processQueue item that
// are strings starting with an "@", using the remaining
// substring as key for the option map,
// e.g. "@autoUpload" is replaced with options.autoUpload:
_transformProcessQueue: function (options) {
var processQueue = [];
$.each(options.processQueue, function () {
var settings = {},
action = this.action,
prefix = this.prefix === true ? action : this.prefix;
$.each(this, function (key, value) {
if ($.type(value) === 'string' &&
value.charAt(0) === '@') {
settings[key] = options[
value.slice(1) || (prefix ? prefix +
key.charAt(0).toUpperCase() + key.slice(1) : key)
];
} else {
settings[key] = value;
}
});
processQueue.push(settings);
});
options.processQueue = processQueue;
},
// Returns the number of files currently in the processsing queue:
processing: function () {
return this._processing;
},
// Processes the files given as files property of the data parameter,
// returns a Promise object that allows to bind callbacks:
process: function (data) {
var that = this,
options = $.extend({}, this.options, data);
if (options.processQueue && options.processQueue.length) {
this._transformProcessQueue(options);
if (this._processing === 0) {
this._trigger('processstart');
}
$.each(data.files, function (index) {
var opts = index ? $.extend({}, options) : options,
func = function () {
if (data.errorThrown) {
return $.Deferred()
.rejectWith(that, [data]).promise();
}
return that._processFile(opts, data);
};
opts.index = index;
that._processing += 1;
that._processingQueue = that._processingQueue.then(func, func)
.always(function () {
that._processing -= 1;
if (that._processing === 0) {
that._trigger('processstop');
}
});
});
}
return this._processingQueue;
},
_create: function () {
this._super();
this._processing = 0;
this._processingQueue = $.Deferred().resolveWith(this)
.promise();
}
});
}));
This diff is collapsed.
/*
* jQuery File Upload Validation Plugin
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2013, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* https://opensource.org/licenses/MIT
*/
/* global define, require, window */
;(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// Register as an anonymous AMD module:
define([
'jquery',
'./jquery.fileupload-process'
], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS:
factory(
require('jquery'),
require('./jquery.fileupload-process')
);
} else {
// Browser globals:
factory(
window.jQuery
);
}
}(function ($) {
'use strict';
// Append to the default processQueue:
$.blueimp.fileupload.prototype.options.processQueue.push(
{
action: 'validate',
// Always trigger this action,
// even if the previous action was rejected:
always: true,
// Options taken from the global options map:
acceptFileTypes: '@',
maxFileSize: '@',
minFileSize: '@',
maxNumberOfFiles: '@',
disabled: '@disableValidation'
}
);
// The File Upload Validation plugin extends the fileupload widget
// with file validation functionality:
$.widget('blueimp.fileupload', $.blueimp.fileupload, {
options: {
/*
// The regular expression for allowed file types, matches
// against either file type or file name:
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
// The maximum allowed file size in bytes:
maxFileSize: 10000000, // 10 MB
// The minimum allowed file size in bytes:
minFileSize: undefined, // No minimal file size
// The limit of files to be uploaded:
maxNumberOfFiles: 10,
*/
// Function returning the current number of files,
// has to be overriden for maxNumberOfFiles validation:
getNumberOfFiles: $.noop,
// Error and info messages:
messages: {
maxNumberOfFiles: 'Maximum number of files exceeded',
acceptFileTypes: 'File type not allowed',
maxFileSize: 'File is too large',
minFileSize: 'File is too small'
}
},
processActions: {
validate: function (data, options) {
if (options.disabled) {
return data;
}
var dfd = $.Deferred(),
settings = this.options,
file = data.files[data.index],
fileSize;
if (options.minFileSize || options.maxFileSize) {
fileSize = file.size;
}
if ($.type(options.maxNumberOfFiles) === 'number' &&
(settings.getNumberOfFiles() || 0) + data.files.length >
options.maxNumberOfFiles) {
file.error = settings.i18n('maxNumberOfFiles');
} else if (options.acceptFileTypes &&
!(options.acceptFileTypes.test(file.type) ||
options.acceptFileTypes.test(file.name))) {
file.error = settings.i18n('acceptFileTypes');
} else if (fileSize > options.maxFileSize) {
file.error = settings.i18n('maxFileSize');
} else if ($.type(fileSize) === 'number' &&
fileSize < options.minFileSize) {
file.error = settings.i18n('minFileSize');
} else {
delete file.error;
}
if (file.error || data.files.error) {
data.files.error = true;
dfd.rejectWith(this, [data]);
} else {
dfd.resolveWith(this, [data]);
}
return dfd.promise();
}
}
});
}));
import * as jQuery from 'jquery';
global.$ = window.$ = jQuery;
import 'bootstrap-sass';
import './widget/file_upload.js';
import '../sass/file_upload.scss';
import 'blueimp-file-upload/js/vendor/jquery.ui.widget';
import 'blueimp-file-upload/js/jquery.iframe-transport';
import 'blueimp-load-image';
//css to convert to less
import 'blueimp-file-upload/css/jquery.fileupload.css';
import 'blueimp-file-upload/css/jquery.fileupload-ui.css';
import '../sass/file_upload.scss';
import 'blueimp-file-upload/js/jquery.fileupload';
import 'blueimp-file-upload/js/jquery.fileupload';
import 'blueimp-file-upload/js/jquery.fileupload-process';
import 'blueimp-file-upload/js/jquery.fileupload-validate';
import 'blueimp-file-upload/js/jquery.fileupload-ui';
import './widget/file_upload.js';
//css to convert to less
import 'blueimp-file-upload/css/jquery.fileupload.css';
import 'blueimp-file-upload/css/jquery.fileupload-ui.css';
......@@ -2,7 +2,6 @@
{% block titrePage %}
{{ parent() }}
Show case: {{ type | capitalize }}
{% endblock %}
......@@ -12,8 +11,7 @@
{% endblock %}
{%- block javascripts %}
{{ parent() }}
{{ parent() }}
{{ encore_entry_script_tags('main') }}
{% endblock %}
{% extends '/base.html.twig' %}
{% block content -%}
{{ form_start(form) }}
<div class="tab-content">
......
var Encore = require('@symfony/webpack-encore');
//var config = Encore.getWebpackConfig();
Encore
// the project directory where compiled assets will be stored
......@@ -36,10 +37,19 @@ Encore
.addEntry('main', [
'./assets/main.js',
'./assets/main.scss',
'./assets/fileupload_demo.js',
])
.splitEntryChunks();
module.exports = Encore.getWebpackConfig();
//module.exports = Encore.getWebpackConfig();
const config = Encore.getWebpackConfig();
config.resolve.alias = {
'load-image': 'blueimp-load-image/js/load-image.js',
'load-image-meta': 'blueimp-load-image/js/load-image-meta.js',
'load-image-exif': 'blueimp-load-image/js/load-image-exif.js',
'load-image-orientation': 'blueimp-load-image/js/load-image-orientation.js',
'load-image-scale': 'blueimp-load-image/js/load-image-scale.js',
'canvas-to-blob': 'blueimp-canvas-to-blob/js/canvas-to-blob.js',
'jquery-ui/widget': 'blueimp-file-upload/js/vendor/jquery.ui.widget.js',
};
module.exports = config;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment