Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Label Database table refactor #14864

Draft
wants to merge 18 commits into
base: develop
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ public static function isDemoMode() {
* @param int $round Round the result to decimals (Default false - No rounding)
* @return float
*/
public static function convertUnit($value, $srcUnit, $dstUnit, $round=false) {
public static function convertUnit($value, string $srcUnit, $dstUnit, $round=false) {
$srcFactor = static::getUnitConversionFactor($srcUnit);
$dstFactor = static::getUnitConversionFactor($dstUnit);
$output = $value * $srcFactor / $dstFactor;
Expand Down
7 changes: 3 additions & 4 deletions app/Http/Controllers/Api/LabelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Controllers\Controller;
use App\Http\Transformers\LabelsTransformer;
use App\Models\Labels\Label;
use App\Models\LabelTemplate;
use Illuminate\Http\Request;
use Illuminate\Support\ItemNotFoundException;
use Illuminate\Support\Facades\Auth;
Expand All @@ -22,13 +23,11 @@ public function index(Request $request)
{
$this->authorize('view', Label::class);

$labels = Label::find();
$labels = LabelTemplate::query();

if ($request->filled('search')) {
$search = $request->get('search');
$labels = $labels->filter(function ($label, $index) use ($search) {
return stripos($label->getName(), $search) !== false;
});
$labels->where('name', 'LIKE', "%{$search}%");
}

$total = $labels->count();
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/LabelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Company;
use App\Models\CustomField;
use App\Models\Labels\Label;
use App\Models\LabelTemplate;
use App\Models\Location;
use App\Models\Manufacturer;
use App\Models\Setting;
Expand All @@ -29,7 +30,8 @@ class LabelsController extends Controller
public function show(string $labelName)
{
$labelName = str_replace('/', '\\', $labelName);
$template = Label::find($labelName);
$template = LabelTemplate::where('name', $labelName)->first();


$exampleAsset = new Asset();

Expand Down Expand Up @@ -89,6 +91,7 @@ public function show(string $labelName)
}
}


return (new LabelView())
->with('assets', collect([$exampleAsset]))
->with('settings', $settings)
Expand Down
67 changes: 35 additions & 32 deletions app/Http/Transformers/LabelsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,66 @@
use App\Models\Labels\Label;
use App\Models\Labels\Sheet;
use App\Models\Labels\RectangleSheet;
use App\Models\LabelTemplate;
use Illuminate\Support\Collection;

class LabelsTransformer
{
public function transformLabels(Collection $labels, $total)
public function transformLabels()
{
$label_templates = LabelTemplate::all();
$total = count($label_templates);
$array = [];
foreach ($labels as $label) {
$array[] = self::transformLabel($label);
foreach ($label_templates as $label_template) {
$array[] = self::transformLabel($label_template);
}

return (new DatatablesTransformer)->transformDatatables($array, $total);
}

public function transformLabel(Label $label)
public function transformLabel(LabelTemplate $label)
{
$array = [
'name' => $label->getName(),
'unit' => $label->getUnit(),
'name' => $label->name,
'unit' => $label->measurement_unit,

'width' => number_format($label->getWidth(), 2),
'height' => number_format($label->getHeight(), 2),
'width' => $label->label_width ? number_format($label->label_width, 3) : number_format($label->tape_width, 3),
'height' => $label->label_height ? number_format($label->label_height, 3) : number_format($label->tape_height, 3),

'margin_top' => $label->getMarginTop(),
'margin_bottom' => $label->getMarginBottom(),
'margin_left' => $label->getMarginLeft(),
'margin_right' => $label->getMarginRight(),
'margin_top' => $label->margin_top,
'margin_bottom' => $label->margin_bottom,
'margin_left' => $label->margin_left,
'margin_right' => $label->margin_right,

'support_asset_tag' => $label->getSupportAssetTag(),
'support_1d_barcode' => $label->getSupport1DBarcode(),
'support_2d_barcode' => $label->getSupport2DBarcode(),
'support_fields' => $label->getSupportFields(),
'support_logo' => $label->getSupportLogo(),
'support_title' => $label->getSupportTitle(),
'tag_option' => $label->tag_option,
'one_d_barcode_option' => $label->one_d_barcode_option,
'two_d_barcode_option' => $label->two_d_barcode_option,
'fields_supported' => $label->fields_supported,
'logo_option' => $label->logo_option,
'title_option' => $label->title_option,
];

if ($label instanceof Sheet) {
if (strpos($label->label_type, 'Sheet') !== false) {
$array['sheet_info'] = [
'label_width' => $label->getLabelWidth(),
'label_height' => $label->getLabelHeight(),
'label_width' => $label->label_width,
'label_height' => $label->label_height,

'label_margin_top' => $label->getLabelMarginTop(),
'label_margin_bottom' => $label->getLabelMarginBottom(),
'label_margin_left' => $label->getLabelMarginLeft(),
'label_margin_right' => $label->getLabelMarginRight(),
'label_margin_top' => $label->margin_top,
'label_margin_bottom' => $label->margin_bottom,
'label_margin_left' => $label->margin_left,
'label_margin_right' => $label->margin_right,

'labels_per_page' => $label->getLabelsPerPage(),
'label_border' => $label->getLabelBorder(),
'labels_per_page' => $label->labelsPerPage(),
'label_border' => $label->LabelBorder(),
];
}

if ($label instanceof RectangleSheet) {
if (strpos($label->label_type, 'Rectangle') !== false) {
$array['rectanglesheet_info'] = [
'columns' => $label->getColumns(),
'rows' => $label->getRows(),
'column_spacing' => $label->getLabelColumnSpacing(),
'row_spacing' => $label->getLabelRowSpacing(),
'columns' => $label->columns(),
'rows' => $label->rows(),
'column_spacing' => $label->columnSpacing(),
'row_spacing' => $label->rowSpacing(),
];
}

Expand Down
Loading