Rapport-Laravel/resources/views/metricview/form.blade.php

483 lines
34 KiB
PHP

@extends('layouts.vertical', ["page_title"=> "Add & Edit Products"])
@section('css')
<!-- third party css -->
<link href="{{asset('assets/libs/select2/select2.min.css')}}" rel="stylesheet" type="text/css" />
<link href="{{asset('assets/libs/multiselect/multiselect.min.css')}}" rel="stylesheet" type="text/css" />
<link href="{{ URL::asset('assets/libs/flatpickr/flatpickr.min.css')}}" rel="stylesheet" type="text/css" />
<!-- third party css end -->
@endsection
@section('content')
<!-- Start Content-->
<div class="container-fluid">
<!-- end page title -->
@if(session()->has('message'))
<div class="alert alert-success mt-3">
{{ session()->get('message') }}
</div>
@endif
<div class="row mt-3">
<div class="col-xl-12">
<div class="card">
<form method="post" action="{{ $form_action ?? url()->current() }}" id="form-availiblity" enctype="multipart/form-data">
@csrf
<div class="card-body">
<div class="row">
<div class="col-md-6 mb-3">
<h4 class="page-title">Add / Edit {{$title}}</h4>
</div>
<div class="col-md-6 mb-3">
<div class="float-end">
<a href="{{$base_url}}s" class="btn btn-dark waves-effect waves-light">Back</a>
<button type="submit" class="btn btn-success waves-effect waves-light">Submit</button>
</div>
</div>
@foreach($fields as $field => $props)
@if($props['type'] != 'hidden')
<div class="col-md-{{isset($props['fullwidth'])?'12':'6'}} mb-3">
<label for="field-{{$field}}" class="form-label">{{$props['title']}} {!!isset($props['required'])&&$props['required'] ? '<span class="text-danger">*</span>':''!!} </label>
@endif
@switch($props['type'])
@case('hidden')
<input type="{{$props['type']}}" id="field-{{$field}}" name="{{$field}}" value="{{$mode=='edit' && isset($item->{$field})?$item->{$field}:''}}">
@break
@case('text')
@case('email')
@case('number')
@case('tel')
<input type="{{$props['type']}}" id="field-{{$field}}" name="{{$field}}" class="form-control" placeholder="Enter {{$props['title']}}" value="{{$mode=='edit'&&isset($item->{$field})?$item->{$field}:''}}" {{isset($props['required'])&&$props['required']?'required':'' }}>
@break
@case('date')
<input type="text" id="field-{{$field}}" name="{{$field}}" class="form-control datepicker" placeholder="Enter {{$props['title']}}" value="{{$mode=='edit'&&isset($item->{$field})?$item->{$field}:''}}" {{isset($props['required'])&&$props['required']?'required':'' }}>
@break
@case('datetime')
<input type="text" id="field-{{$field}}" name="{{$field}}" class="form-control datetimepicker" placeholder="Enter {{$props['title']}}" value="{{$mode=='edit'&&isset($item->{$field})?$item->{$field}:''}}" {{isset($props['required'])&&$props['required']?'required':'' }}>
@break
@case('textarea')
<textarea id="field-{{$field}}" name="{{$field}}" class="form-control" placeholder="Enter {{$props['title']}}" {{isset($props['required'])&&$props['required']?'required':'' }}>{{$mode=='edit'?$item->{$field}:''}}</textarea>
@break
@case('select')
<select class="form-control" id="field-{{$field}}" name="{{$field}}" {{isset($props['required'])&&$props['required']?'required':'' }} @if($field === 'type') data-metric-view-type="1" @endif>
<option value=""> -- Select {{$props['title']}} -- </option>
@foreach($props['values'] as $k => $v)
<option value="{{$k}}" {{ isset($item->{$field}) && $item->{$field} == $k ? 'selected="selected"':''}}>{{$v}}</option>
@endforeach
</select>
@break
@case('multiselect')
<select class="form-control select2-multiple" data-toggle="select2" data-width="100%" multiple="multiple" data-placeholder="Choose {{$props['title']}}" id="field-{{$field}}" name="{{$field}}[]" {{isset($props['required'])&&$props['required']?'required':'' }}>
<option value=""> -- Select {{$props['title']}} -- </option>
@foreach($props['values'] as $k => $v)
<option value="{{$k}}" {{$mode=='edit' && isset($item->{$field}) && in_array($k, $item->{$field}) ? 'selected="selected"':''}}>{{$v}}</option>
@endforeach
</select>
@break
@case('bigmultiselect')
<select multiple="multiple" class="bigmultiselect multi-select" id="field-{{$field}}" name="{{$field}}[]" {{isset($props['required'])&&$props['required']?'required':'' }}>
@foreach($props['values'] as $k => $v)
<option value="{{$k}}" {{$mode=='edit' && in_array($k, $item->{$field}) ? 'selected="selected"':''}}>{{$v}}</option>
@endforeach
</select>
@break
@case('yesno')
<div>
<div class="form-check mb-2 form-check-success form-check-inline">
<input class="form-check-input" type="radio" name="{{$field}}" id="field-{{$field}}-yes" value="yes" {{$mode=='edit' && $item->{$field} == 'yes' ? 'checked':''}} {{isset($props['required'])&&$props['required']?'required':'' }}>
<label class="form-check-label" for="field-{{$field}}-yes">Yes</label>
</div>
<div class="form-check mb-2 form-check-danger form-check-inline">
<input class="form-check-input" type="radio" name="{{$field}}" id="field-{{$field}}-no" value="no" {{$mode=='edit' && $item->{$field} == 'no' ? 'checked':''}}>
<label class="form-check-label" for="field-{{$field}}-no">No</label>
</div>
</div>
@break
@case('image')
<div class="mt-3" id="file_wrapper">
<input type="file" name="{{$field}}" class="dropify" data-default-file="{{$mode=='edit'?$item->{$field}:''}}" data-allowed-file-extensions="png jpg jpeg gif" />
<p class="text-muted text-center mt-2 mb-0">500MB Max File size</p>
</div>
@break
@case('file')
<div class="mt-3" id="file_wrapper">
<input type="file" name="{{$field}}" class="dropify" data-default-file="{{$mode=='edit'?$item->{$field}:''}}" data-allowed-file-extensions="png jpg jpeg gif mp4 pdf mp3 zip" />
<p class="text-muted text-center mt-2 mb-0">1GB Max File size</p>
</div>
@break
@case('mapping')
<div><button type="button" class="btn btn-info btn-xs float-end" id="btn-add-mapping">Add Mapping</button></div>
<table class="table mb-0" id="table-metrics">
<thead>
<tr>
<th>Metric</th>
<th>Display Unit</th>
<th>Sort Order</th>
<th>Weight</th>
<th>List View?</th>
</tr>
</thead>
<tbody>
@if($mode=='edit')
@foreach($item->{$field} as $map)
<tr>
<td>
<select class="form-control metric-select" name="metric[]" required>
<option value=""> -- Select Metric -- </option>
@foreach($props['metrics'] as $k => $v)
<option value="{{$k}}" {{$map->metric == $k ? 'selected="selected"':''}}>{{$v}}</option>
@endforeach
</select>
</td>
<td><input type="text" name="display_unit[]" class="form-control" value="{{$map->display}}"></td>
<td><input type="number" name="sort_order[]" class="form-control" value="{{isset($map->sort_order)?$map->sort_order:0}}"></td>
<td><input type="number" name="weight[]" class="form-control" value="{{isset($map->weight)?$map->weight:1}}"></td>
<td><select name="list_view[]" class="form-control">
<option value="yes" {{isset($map->list_view)&&$map->list_view=='yes'?'selected':''}}>Yes</option>
<option value="no" {{isset($map->list_view)&&$map->list_view=='no'?'selected':''}}>No</option>
</select></td>
<th><button type="button" class="btn btn-danger waves-effect waves-light btn-remove"><i class="mdi mdi-close"></i></button></th>
</tr>
@endforeach
@else
<tr>
<td>
<select class="form-control metric-select" name="metric[]" required>
<option value=""> -- Select Metric -- </option>
@foreach($props['metrics'] as $k => $v)
<option value="{{$k}}">{{$v}}</option>
@endforeach
</select>
</td>
<td><input type="text" name="display_unit[]" class="form-control" value=""></td>
<td><input type="number" name="sort_order[]" class="form-control" value=""></td>
<td><input type="number" name="weight[]" class="form-control" value="1"></td>
<td><select name="list_view[]" class="form-control">
<option value="yes">Yes</option>
<option value="no">No</option>
</select></td>
<th><button type="button" class="btn btn-danger waves-effect waves-light btn-remove"><i class="mdi mdi-close"></i></button></th>
</tr>
@endif
</tbody>
</table>
@break
@case('color')
@php
$colorValue = ($mode == 'edit' && isset($item->{$field}) && $item->{$field} !== '')
? $item->{$field}
: '#000000';
if (!preg_match('/^#[0-9A-Fa-f]{6}$/', $colorValue)) {
$colorValue = '#000000';
}
@endphp
<div class="d-flex align-items-center gap-2">
<input type="color"
class="form-control form-control-color color-picker-input"
value="{{ $colorValue }}"
style="width: 3.5rem; padding: 0.2rem;"
data-color-target="field-{{$field}}">
<input type="text"
id="field-{{$field}}"
name="{{$field}}"
class="form-control color-hex-input"
placeholder="#RRGGBB"
pattern="^#([A-Fa-f0-9]{6})$"
value="{{ $mode=='edit' && isset($item->{$field}) && $item->{$field} !== '' ? $item->{$field} : '#000000' }}"
{{isset($props['required'])&&$props['required']?'required':'' }}>
</div>
@break
@case('color_ranges')
<div><button type="button" class="btn btn-info btn-xs float-end" id="btn-add-color-range">Add Range</button></div>
<table class="table mb-0" id="table-color-ranges">
<thead>
<tr>
<th width="25%">Min (%)</th>
<th width="25%">Max (%)</th>
<th width="40%">Color</th>
<th width="10%">Delete</th>
</tr>
</thead>
<tbody>
@php
$existingRanges = ($mode == 'edit' && isset($item->{$field}) && is_array($item->{$field}))
? $item->{$field}
: [];
@endphp
@if(count($existingRanges) > 0)
@foreach($existingRanges as $range)
@php
$rangeColor = isset($range->color) && preg_match('/^#[0-9A-Fa-f]{6}$/', $range->color)
? $range->color
: '#000000';
@endphp
<tr>
<td><input type="number" name="color_ranges[min][]" class="form-control" min="0" max="100" step="1" placeholder="0" value="{{ $range->min ?? '' }}"></td>
<td><input type="number" name="color_ranges[max][]" class="form-control" min="0" max="100" step="1" placeholder="100" value="{{ $range->max ?? '' }}"></td>
<td>
<div class="d-flex align-items-center gap-2">
<input type="color" class="form-control form-control-color color-picker-input" value="{{ $rangeColor }}" style="width: 3.5rem; padding: 0.2rem;">
<input type="text" name="color_ranges[color][]" class="form-control color-hex-input" placeholder="#RRGGBB" pattern="^#([A-Fa-f0-9]{6})$" value="{{ $range->color ?? $rangeColor }}">
</div>
</td>
<td><button type="button" class="btn btn-danger waves-effect waves-light btn-remove"><i class="mdi mdi-close"></i></button></td>
</tr>
@endforeach
@else
<tr>
<td><input type="number" name="color_ranges[min][]" class="form-control" min="0" max="100" step="1" placeholder="0" value="0"></td>
<td><input type="number" name="color_ranges[max][]" class="form-control" min="0" max="100" step="1" placeholder="100" value="100"></td>
<td>
<div class="d-flex align-items-center gap-2">
<input type="color" class="form-control form-control-color color-picker-input" value="#000000" style="width: 3.5rem; padding: 0.2rem;">
<input type="text" name="color_ranges[color][]" class="form-control color-hex-input" placeholder="#RRGGBB" pattern="^#([A-Fa-f0-9]{6})$" value="#000000">
</div>
</td>
<td><button type="button" class="btn btn-danger waves-effect waves-light btn-remove"><i class="mdi mdi-close"></i></button></td>
</tr>
@endif
</tbody>
</table>
@break
@case('combined_metrics')
<div><button type="button" class="btn btn-info btn-xs float-end" id="btn-add-metric">Add Metric</button></div>
<table class="table mb-0" id="table-combined">
<thead>
<tr>
<th width="10%">Type</th>
<th width="10%">Title</th>
<th width="65%">Include Metrics</th>
<th width="8%">List View?</th>
<th width="7%">Delete?</th>
</tr>
</thead>
<tbody>
@if($mode=='edit')
@foreach(json_decode($item->{$field}) as $i => $map)
<tr>
<td>
<select class="form-control" name="combined_metrics[type][]" required>
<option value=""> -- Select Type -- </option>
<option value="prescribers" {{$map->type == 'prescribers' ? 'selected':''}}>Prescribers (no of)</option>
<option value="unique_new" {{$map->type == 'unique_new' ? 'selected':''}}>Unique New Prescribers (launch)</option>
<option value="combination" {{$map->type == 'combination' ? 'selected':''}}>Combination (Total)</option>
<option value="mtd" {{$map->type == 'mtd' ? 'selected':''}}>MTD Value</option>
<option value="ytd" {{$map->type == 'ytd' ? 'selected':''}}>YTD Value</option>
<option value="financial_ytd" {{$map->type == 'financial_ytd' ? 'selected':''}}>Financial YTD Value</option>
<option value="overall_metrics" {{$map->type == 'overall_metrics' ? 'selected':''}}>Overall Metrics</option>
<option value="unit_for_ranking" {{$map->type == 'unit_for_ranking' ? 'selected':''}}>Units For Ranking</option>
<option value="active_user" {{$map->type == 'active_user' ? 'selected':''}}>Active Users</option>
<option value="mtd_comparison" {{$map->type == 'mtd_comparison' ? 'selected':''}}>MTD Comparison</option>
</select>
</td>
<td><input type="text" name="combined_metrics[title][]" class="form-control" value="{{isset($map->title)?$map->title:''}}"></td>
<td><select class="form-control select2-multiple" data-toggle="select2" data-width="100%" multiple="multiple" data-placeholder="Choose Metrics" name="combined_metrics[fields][{{$i}}][]">
<option value=""> -- Select Multiple Metrics -- </option>
@foreach($fields['metrics']['metrics'] as $k => $v)
<option value="{{$k}}" {{isset($map->fields) && is_array($map->fields) && in_array($k, $map->fields) ? 'selected="selected"':''}}>{{$v}}</option>
@endforeach
</select>
</td>
<td><select name="combined_metrics[list_view][]" class="form-control">
<option value="no" {{isset($map->list_view)&&$map->list_view=='no'?'selected':''}}>No</option>
<option value="yes" {{isset($map->list_view)&&$map->list_view=='yes'?'selected':''}}>Yes</option>
</select></td>
<th><button type="button" class="btn btn-danger waves-effect waves-light btn-remove"><i class="mdi mdi-close"></i></button></th>
</tr>
@endforeach
@endif
</tbody>
</table>
@break
@endswitch
@if($props['type'] != 'hidden')
</div>
@endif
@endforeach
<div class="col-md-12 mb-3">
<div class="float-end">
<a href="{{$base_url}}s" class="btn btn-dark waves-effect waves-light">Back</a>
<button type="submit" class="btn btn-success waves-effect waves-light">Submit</button>
</div>
</div>
</div>
</div> <!-- end card-body -->
</form>
</div> <!-- end card-->
</div> <!-- end col -->
</div>
</div>
<style type="text/css">
.ms-container {max-width: 100%}
.gap-2 { gap: 0.5rem; }
.form-control-color { min-height: 38px; }
</style>
@endsection
@section('script')
<script src="{{asset('assets/libs/select2/select2.min.js')}}"></script>
<script src="{{asset('assets/libs/multiselect/multiselect.min.js')}}"></script>
<script src="{{ URL::asset('assets/libs/flatpickr/flatpickr.min.js')}}"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.datepicker').flatpickr({
dateFormat: "m/d/Y"
});
$('.datetimepicker').flatpickr({
enableTime: true,
dateFormat: "m/d/Y H:i"
});
$('[data-metric-view-type="1"]').on('change', function() {
const selectedType = $(this).val();
if (!selectedType) {
return;
}
@if($mode === 'edit' && isset($item->id) && $item->id !== '')
window.location.href = '{{ $base_url }}/edit?id={{ $item->id }}&type=' + selectedType;
@else
window.location.href = '{{ $base_url }}/addnew?type=' + selectedType;
@endif
});
function initMetricSelect2($context) {
($context || $('#table-metrics')).find('select.metric-select').each(function() {
let $select = $(this);
if ($select.hasClass('select2-hidden-accessible')) {
$select.select2('destroy');
}
$select.select2({
width: '100%',
placeholder: '-- Select Metric --',
allowClear: true
});
});
}
$('[data-toggle="select2"]').select2();
initMetricSelect2();
function bindColorPickers($context) {
const $root = $context || $(document);
$root.find('.color-picker-input').each(function() {
const $picker = $(this);
let $hex = $picker.data('color-target')
? $('#' + $picker.data('color-target'))
: $picker.closest('td, .d-flex').find('.color-hex-input').first();
if (!$hex.length) {
return;
}
$picker.off('input.colorSync change.colorSync').on('input.colorSync change.colorSync', function() {
$hex.val($(this).val().toUpperCase());
});
$hex.off('input.colorSync change.colorSync').on('input.colorSync change.colorSync', function() {
const val = $(this).val().trim();
if (/^#[0-9A-Fa-f]{6}$/.test(val)) {
$picker.val(val);
}
});
});
}
function bindRemoveButtons() {
$('.btn-remove').off('click').on('click', function() {
$(this).closest('tr').remove();
});
}
bindColorPickers();
bindRemoveButtons();
$('#btn-add-color-range').click(function() {
$('table#table-color-ranges tbody').append(`<tr>
<td><input type="number" name="color_ranges[min][]" class="form-control" min="0" max="100" step="1" placeholder="0" value=""></td>
<td><input type="number" name="color_ranges[max][]" class="form-control" min="0" max="100" step="1" placeholder="100" value=""></td>
<td>
<div class="d-flex align-items-center gap-2">
<input type="color" class="form-control form-control-color color-picker-input" value="#000000" style="width: 3.5rem; padding: 0.2rem;">
<input type="text" name="color_ranges[color][]" class="form-control color-hex-input" placeholder="#RRGGBB" pattern="^#([A-Fa-f0-9]{6})$" value="#000000">
</div>
</td>
<td><button type="button" class="btn btn-danger waves-effect waves-light btn-remove"><i class="mdi mdi-close"></i></button></td>
</tr>`);
bindColorPickers($('table#table-color-ranges tbody tr').last());
bindRemoveButtons();
});
@if(isset($fields['metrics']))
$('#btn-add-mapping').click(function(){
$('table#table-metrics tbody').append(`<tr>
<td>
<select class="form-control metric-select" name="metric[]" required>
<option value=""> -- Select Metric -- </option>
@foreach($fields['metrics']['metrics'] as $k => $v)
<option value="{{$k}}">{{$v}}</option>
@endforeach
</select>
</td>
<td><input type="text" name="display_unit[]" class="form-control" value=""></td>
<td><input type="number" name="sort_order[]" class="form-control" value=""></td>
<td><input type="number" name="weight[]" class="form-control" value="1"></td>
<td><select name="list_view[]" class="form-control">
<option value="yes">Yes</option>
<option value="no">No</option>
</select></td>
<th><button type="button" class="btn btn-danger waves-effect waves-light btn-remove"><i class="mdi mdi-close"></i></button></th>
</tr>`);
initMetricSelect2($('table#table-metrics tbody tr').last());
bindRemoveButtons();
$('.cust-date').unbind();
$('.cust-date').flatpickr();
});
let comcount = 100;
$('#btn-add-metric').click(function(){
console.log("add com m")
$('table#table-combined tbody').append(`<tr>
<td>
<select class="form-control" name="combined_metrics[type][${comcount}]" required>
<option value=""> -- Select Type -- </option>
<option value="prescribers">Prescribers (no of)</option>
<option value="unique_new">Unique New Prescribers (launch)</option>
<option value="combination">Combination (Total)</option>
<option value="mtd">MTD Value</option>
<option value="ytd">YTD Value</option>
<option value="financial_ytd">Financial YTD Value</option>
<option value="overall_metrics">Overall Metrics</option>
<option value="unit_for_ranking">Unit For Ranking</option>
<option value="active_user">Active User</option>
<option value="mtd_comparison">MTD Comparison</option>
</select>
</td>
<td><input type="text" name="combined_metrics[title][${comcount}]" class="form-control" value=""></td>
<td><select class="form-control select2-multiple" data-toggle="select2" data-width="100%" multiple="multiple" data-placeholder="Choose Metrics" name="combined_metrics[fields][${comcount}][]">
<option value=""> -- Select Multiple Metrics -- </option>
@foreach($fields['metrics']['metrics'] as $k => $v)
<option value="{{$k}}">{{$v}}</option>
@endforeach
</select>
</td>
<th><button type="button" class="btn btn-danger waves-effect waves-light btn-remove"><i class="mdi mdi-close"></i></button></th>
</tr>`);
$('[data-toggle="select2"]').select2();
bindRemoveButtons();
$('.cust-date').unbind();
$('.cust-date').flatpickr();
comcount++;
});
@endif
});
</script>
@endsection