Skip to content

A free open source IT asset/license management system

Merge pull request #12708 from uberbrady/livewire_importer_no_subcomponent

snipe473211397f5d
diff --cc app/Helpers/Helper.php
index 89704242ba,3692c9c1f7..df498da8c9
--- a/app/Helpers/Helper.php
+++ b/app/Helpers/Helper.php
@@@ -1126,60 -1144,42 +1144,77 @@@ class Helpe
return $settings;
}
- public static function AgeFormat($date) {
- $year = Carbon::parse($date)
- ->diff(now())->y;
- $month = Carbon::parse($date)
- ->diff(now())->m;
- $days = Carbon::parse($date)
- ->diff(now())->d;
- $age='';
- if ($year) {
- $age .= $year.'y ';
- }
- if ($month) {
- $age .= $month.'m ';
- }
- if ($days) {
- $age .= $days.'d';
- }
- return $age;
+
+ /**
+ * Generic helper (largely used by livewire right now) that returns the font-awesome icon
+ * for the object type.
+ *
+ * @author A. Gianotto <[email protected]>
+ * @since 6.1.0
+ *
+ * @return string
+ */
+ public static function iconTypeByItem($item) {
+
+ switch ($item) {
+ case 'asset':
+ return 'fas fa-barcode';
+ break;
+ case 'accessory':
+ return 'fas fa-keyboard';
+ break;
+ case 'component':
+ return 'fas fa-hdd';
+ break;
+ case 'consumable':
+ return 'fas fa-tint';
+ break;
+ case 'license':
+ return 'far fa-save';
+ break;
+ case 'location':
+ return 'fas fa-map-marker-alt';
+ break;
+ case 'user':
+ return 'fas fa-user';
+ break;
+ }
}
+
+
+ /*
+ * This is a shorter way to see if the app is in demo mode.
+ *
+ * This makes it cleanly available in blades and in controllers, e.g.
+ *
+ * Blade:
+ * {{ Helper::isDemoMode() ? ' disabled' : ''}} for form blades where we need to disable a form
+ *
+ * Controller:
+ * if (Helper::isDemoMode()) {
+ * // don't allow the thing
+ * }
+ * @todo - use this everywhere else in the app where we have very long if/else config('app.lock_passwords') stuff
+ */
+ public static function isDemoMode() {
+ if (config('app.lock_passwords') === true) {
+ return true;
+ \Log::debug('app locked!');
+ }
+
+ return false;
+ }
+
+
+ /*
+ * I know it's gauche to return a shitty HTML string, but this is just a helper and since it will be the same every single time,
+ * it seemed pretty safe to do here. Don't you judge me.
+ */
+ public static function showDemoModeFieldWarning() {
+ if (Helper::isDemoMode()) {
+ return "<p class=\"text-warning\"><i class=\"fas fa-lock\"></i>" . trans('general.feature_disabled') . "</p>";
+ }
+ }
}