Skip to content

Commit

Permalink
Allow multiple upload fields and add logo option to labels (#6736)
Browse files Browse the repository at this point in the history
* Change upload js to work with multiple upload elements on a single page

* Change uploadFile in upload modal and form partial

* Change uploadFile to js-uploadFile to avoid potential issues in the future

* Remove duplicate style attribute causing webpack to fail

* Missed a css class in rename to js- prefix

* - Move logo uploads to partial for eaiser usage
- Add label logo
- Add css classes to label elements
- Change label prefix text (M: S: ...) to css::before content for easy removal in config

* Add more css classes to labels

* Allow unescaped " (quot) in css ouput

* Add max size param to partial, set defaults for allowedType and size
  • Loading branch information
smb authored and snipe committed Mar 1, 2019
1 parent c47fa5a commit e1907e3
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 163 deletions.
41 changes: 33 additions & 8 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,13 @@ public function postBranding(ImageUploadRequest $request)
$setting->brand = 1;

// If they are uploading an image, validate it and upload it
} elseif ($request->hasFile('image')) {
$image = $request->file('image');
} elseif ($request->hasFile('logo')) {
$image = $request->file('logo');
$ext = $image->getClientOriginalExtension();
$setting->logo = $file_name = 'logo.' . $ext;

if ('svg' != $image->getClientOriginalExtension()) {
$upload = Image::make($image->getRealPath())->resize(null, 150, function($constraint) {
$upload = Image::make($image->getRealPath())->resize(null, 150, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
Expand All @@ -438,14 +438,14 @@ public function postBranding(ImageUploadRequest $request)
Storage::disk('public')->delete($setting->email_logo);
$setting->email_logo = null;

// If they are uploading an image, validate it and upload it
// If they are uploading an image, validate it and upload it
} elseif ($request->hasFile('email_logo')) {
$email_image = $email_upload = $request->file('email_logo');
$email_ext = $email_image->getClientOriginalExtension();
$setting->email_logo = $email_file_name = 'email_logo.' . $email_ext;

if ('svg' != $email_image->getClientOriginalExtension()) {
$email_upload = Image::make($email_image->getRealPath())->resize(null, 100, function($constraint) {
$email_upload = Image::make($email_image->getRealPath())->resize(null, 100, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
Expand All @@ -460,21 +460,46 @@ public function postBranding(ImageUploadRequest $request)
}
}

// If the user wants to clear the label logo...
if ('1' == $request->input('clear_label_logo')) {
Storage::disk('public')->delete($setting->label_logo);
$setting->label_logo = null;

// If they are uploading an image, validate it and upload it
} elseif ($request->hasFile('label_logo')) {
$image = $request->file('label_logo');
$ext = $image->getClientOriginalExtension();
$setting->label_logo = $label_file_name = 'label_logo.' . $ext;

if ('svg' != $image->getClientOriginalExtension()) {
$upload = Image::make($image->getRealPath())->resize(null, 100, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
}

// This requires a string instead of an object, so we use ($string)
Storage::disk('public')->put($label_file_name, (string) $upload->encode());

// Remove Current image if exists
if (($setting->label_logo) && (file_exists($label_file_name))) {
Storage::disk('public')->delete($label_file_name);
}
}

// If the user wants to clear the favicon...
if ('1' == $request->input('clear_favicon')) {
Storage::disk('public')->delete($setting->clear_favicon);
$setting->favicon = null;

// If they are uploading an image, validate it and upload it
// If they are uploading an image, validate it and upload it
} elseif ($request->hasFile('favicon')) {

$favicon_image = $favicon_upload = $request->file('favicon');
$favicon_ext = $favicon_image->getClientOriginalExtension();
$setting->favicon = $favicon_file_name = 'favicon-uploaded.' . $favicon_ext;

if (('ico' != $favicon_image->getClientOriginalExtension()) && ('svg' != $favicon_image->getClientOriginalExtension())) {
$favicon_upload = Image::make($favicon_image->getRealPath())->resize(null, 36, function($constraint) {
$favicon_upload = Image::make($favicon_image->getRealPath())->resize(null, 36, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
Expand Down
9 changes: 5 additions & 4 deletions app/Models/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ public function show_custom_css(): string
// Needed for modifying the bootstrap nav :(
$custom_css = str_ireplace('script', 'SCRIPTS-NOT-ALLOWED-HERE', $custom_css);
$custom_css = str_replace('>', '>', $custom_css);
// Allow String output (needs quotes)
$custom_css = str_replace('"', '"', $custom_css);

return $custom_css;
}
Expand Down Expand Up @@ -320,17 +322,17 @@ public static function passwordComplexityRulesSaving($action = 'update'): string

/**
* Get the specific LDAP settings
*
*
* @author Wes Hulette <jwhulette@gmail.com>
*
*
* @since 5.0.0
*
* @return Collection
*/
public static function getLdapSettings(): Collection
{
$ldapSettings = self::select([
'ldap_enabled',
'ldap_enabled',
'ldap_server',
'ldap_uname',
'ldap_pword',
Expand All @@ -354,5 +356,4 @@ public static function getLdapSettings(): Collection

return collect($ldapSettings);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddLabelLogoToSettings extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('settings', function (Blueprint $table) {
$table->char('label_logo')->nullable()->default(null);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('settings', function (Blueprint $table) {
$table->dropColumn('email_logo');
});
}
}
3 changes: 1 addition & 2 deletions resources/assets/js/components/importer/importer-file.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@
<br><br>
</div>

<div class="alert col-md-12" style="padding-top: 20px;"
<div class="alert col-md-12" style="padding-top: 20px; text-align:left; "
:class="alertClass"
style="text-align:left"
v-if="statusText">
{{ this.statusText }}
</div>
Expand Down
36 changes: 20 additions & 16 deletions resources/assets/js/snipeit.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,11 @@ $(document).ready(function () {


// Image preview
function readURL(input) {
function readURL(input, $preview) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#imagePreview').attr('src', e.target.result);
$preview.attr('src', e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
Expand All @@ -436,28 +436,32 @@ $(document).ready(function () {
}

// File size validation
$('#uploadFile').bind('change', function() {
$('#upload-file-status').removeClass('text-success').removeClass('text-danger');
$('.goodfile').remove();
$('.badfile').remove();
$('.badfile').remove();
$('.previewSize').hide();
$('#upload-file-info').html('');

var max_size = $('#uploadFile').data('maxsize');
$('.js-uploadFile').bind('change', function() {
let $this = $(this);
let id = '#' + $this.attr('id');
let status = id + '-status';
let $status = $(status);
$status.removeClass('text-success').removeClass('text-danger');
$(status + ' .goodfile').remove();
$(status + ' .badfile').remove();
$(status + ' .previewSize').hide();
$(id + '-info').html('');

var max_size = $this.data('maxsize');
var total_size = 0;

for (var i = 0; i < this.files.length; i++) {
total_size += this.files[i].size;
$('#upload-file-info').append('<span class="label label-default">' + this.files[i].name + ' (' + formatBytes(this.files[i].size) + ')</span> ');
$(id + '-info').append('<span class="label label-default">' + this.files[i].name + ' (' + formatBytes(this.files[i].size) + ')</span> ');
}

if (total_size > max_size) {
$('#upload-file-status').addClass('text-danger').removeClass('help-block').prepend('<i class="badfile fa fa-times"></i> ').append('<span class="previewSize"> Upload is ' + formatBytes(total_size) + '.</span>');
$status.addClass('text-danger').removeClass('help-block').prepend('<i class="badfile fa fa-times"></i> ').append('<span class="previewSize"> Upload is ' + formatBytes(total_size) + '.</span>');
} else {
$('#upload-file-status').addClass('text-success').removeClass('help-block').prepend('<i class="goodfile fa fa-check"></i> ');
readURL(this);
$('#imagePreview').fadeIn();
$status.addClass('text-success').removeClass('help-block').prepend('<i class="goodfile fa fa-check"></i> ');
let $preview = $(id + '-imagePreview');
readURL(this, $preview);
$preview.fadeIn();
}


Expand Down
52 changes: 27 additions & 25 deletions resources/lang/en/admin/settings/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,41 @@
'admin_cc_email' => 'CC Email',
'admin_cc_email_help' => 'If you would like to send a copy of checkin/checkout emails that are sent to users to an additional email account, enter it here. Otherwise leave this field blank.',
'is_ad' => 'This is an Active Directory server',
'alert_email' => 'Send alerts to',
'alerts_enabled' => 'Email Alerts Enabled',
'alert_interval' => 'Expiring Alerts Threshold (in days)',
'alert_inv_threshold' => 'Inventory Alert Threshold',
'asset_ids' => 'Asset IDs',
'audit_interval' => 'Audit Interval',
'alert_email' => 'Send alerts to',
'alerts_enabled' => 'Email Alerts Enabled',
'alert_interval' => 'Expiring Alerts Threshold (in days)',
'alert_inv_threshold' => 'Inventory Alert Threshold',
'asset_ids' => 'Asset IDs',
'audit_interval' => 'Audit Interval',
'audit_interval_help' => 'If you are required to regularly physically audit your assets, enter the interval in months.',
'audit_warning_days' => 'Audit Warning Threshold',
'audit_warning_days' => 'Audit Warning Threshold',
'audit_warning_days_help' => 'How many days in advance should we warn you when assets are due for auditing?',
'auto_increment_assets' => 'Generate auto-incrementing asset IDs',
'auto_increment_prefix' => 'Prefix (optional)',
'auto_incrementing_help' => 'Enable auto-incrementing asset IDs first to set this',
'backups' => 'Backups',
'barcode_settings' => 'Barcode Settings',
'auto_increment_assets' => 'Generate auto-incrementing asset IDs',
'auto_increment_prefix' => 'Prefix (optional)',
'auto_incrementing_help' => 'Enable auto-incrementing asset IDs first to set this',
'backups' => 'Backups',
'barcode_settings' => 'Barcode Settings',
'confirm_purge' => 'Confirm Purge',
'confirm_purge_help' => 'Enter the text "DELETE" in the box below to purge your deleted records. This action cannot be undone.',
'custom_css' => 'Custom CSS',
'custom_css_help' => 'Enter any custom CSS overrides you would like to use. Do not include the &lt;style&gt;&lt;/style&gt; tags.',
'custom_css' => 'Custom CSS',
'custom_css_help' => 'Enter any custom CSS overrides you would like to use. Do not include the &lt;style&gt;&lt;/style&gt; tags.',
'custom_forgot_pass_url' => 'Custom Password Reset URL',
'custom_forgot_pass_url_help' => 'This replaces the built-in forgotten password URL on the login screen, useful to direct people to internal or hosted LDAP password reset functionality. It will effectively disable local user forgotten password functionality.',
'dashboard_message' => 'Dashboard Message',
'dashboard_message_help' => 'This text will appear on the dashboard for anyone with permission to view the dashboard.',
'default_currency' => 'Default Currency',
'default_eula_text' => 'Default EULA',
'default_currency' => 'Default Currency',
'default_eula_text' => 'Default EULA',
'default_language' => 'Default Language',
'default_eula_help_text' => 'You can also associate custom EULAs to specific asset categories.',
'default_eula_help_text' => 'You can also associate custom EULAs to specific asset categories.',
'display_asset_name' => 'Display Asset Name',
'display_checkout_date' => 'Display Checkout Date',
'display_eol' => 'Display EOL in table view',
'display_qr' => 'Display Square Codes',
'display_alt_barcode' => 'Display 1D barcode',
'display_alt_barcode' => 'Display 1D barcode',
'email_logo' => 'Email Logo',
'barcode_type' => '2D Barcode Type',
'alt_barcode_type' => '1D barcode type',
'email_logo_size' => 'Square logos in email look best.',
'barcode_type' => '2D Barcode Type',
'alt_barcode_type' => '1D barcode type',
'email_logo_size' => 'Square logos in email look best. ',
'eula_settings' => 'EULA Settings',
'eula_markdown' => 'This EULA allows <a href="https://help.github.com/articles/github-flavored-markdown/">Github flavored markdown</a>.',
'favicon' => 'Favicon',
Expand All @@ -50,9 +50,11 @@
'footer_text' => 'Additional Footer Text ',
'footer_text_help' => 'This text will appear in the right-side footer. Links are allowed using <a href="https://help.github.com/articles/github-flavored-markdown/">Github flavored markdown</a>. Line breaks, headers, images, etc may result in unpredictable results.',
'general_settings' => 'General Settings',
'generate_backup' => 'Generate Backup',
'generate_backup' => 'Generate Backup',
'header_color' => 'Header Color',
'info' => 'These settings let you customize certain aspects of your installation.',
'label_logo' => 'Label Logo',
'label_logo_size' => 'Square logos look best - will be displayed in the top right of each asset label. ',
'laravel' => 'Laravel Version',
'ldap_enabled' => 'LDAP enabled',
'ldap_integration' => 'LDAP Integration',
Expand All @@ -61,9 +63,9 @@
'ldap_login_sync_help' => 'This only tests that LDAP can sync correctly. If your LDAP Authentication query is not correct, users may still not be able to login. YOU MUST SAVE YOUR UPDATED LDAP SETTINGS FIRST.',
'ldap_server' => 'LDAP Server',
'ldap_server_help' => 'This should start with ldap:// (for unencrypted or TLS) or ldaps:// (for SSL)',
'ldap_server_cert' => 'LDAP SSL certificate validation',
'ldap_server_cert_ignore' => 'Allow invalid SSL Certificate',
'ldap_server_cert_help' => 'Select this checkbox if you are using a self signed SSL cert and would like to accept an invalid SSL certificate.',
'ldap_server_cert' => 'LDAP SSL certificate validation',
'ldap_server_cert_ignore' => 'Allow invalid SSL Certificate',
'ldap_server_cert_help' => 'Select this checkbox if you are using a self signed SSL cert and would like to accept an invalid SSL certificate.',
'ldap_tls' => 'Use TLS',
'ldap_tls_help' => 'This should be checked only if you are running STARTTLS on your LDAP server. ',
'ldap_uname' => 'LDAP Bind Username',
Expand Down
Loading

0 comments on commit e1907e3

Please sign in to comment.