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

Mass management of state of instances #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions app/Http/Controllers/BatchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,32 @@ public function instanceStore(StoreBatchInstanceRequest $request): RedirectRespo
->withErrors($errors);
}

public function instancesList(Request $request): View {
$instanceController = new InstanceController();
$statusList = $instanceController->getStatusList();

return view('admin.batch.instances')
->with('statusList', $statusList);
}

public function getInstancesData(Request $request)
{
return datatables()
->of(Instance::query())
->addColumn('checkbox', function ($instance) {
return '<input type="checkbox" data-id="'.$instance->id.'">';
})
->rawColumns(['checkbox'])
->make(true);
}

public function updateStatus(Request $request)
{
$ids = $request->input('ids');
$status = $request->input('status');

Instance::whereIn('id', $ids)->update(['status' => $status]);

return response()->json(['message' => __('status.updated_successfully')]);
}
}
10 changes: 10 additions & 0 deletions app/Http/Controllers/InstanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ public function getInstances(Request $request): JsonResponse {
return new HtmlString('<a href="' . route('myagora.instances', ['code' => $instance->client->code]) . '">' .
$instance->client->name . '</a><br/>' . $instance->client->dns . ' - ' . $instance->client->code);
})
->addColumn('client_code', function ($instance) {
return new HtmlString($instance->client->code);
})
->addColumn('client_dns', function ($instance) {
return new HtmlString($instance->client->dns);
})
->addColumn('type', function ($instance) {
return new HtmlString($instance->client->type->name . '<br/>' .
$instance->modelType->description);
Expand Down Expand Up @@ -352,6 +358,10 @@ public function getInstances(Request $request): JsonResponse {
->addColumn('actions', static function ($instance) {
return view('admin.instance.action', ['instance' => $instance]);
})
->addColumn('checkbox', function ($instance) {
return '<input type="checkbox" data-id="'.$instance->id.'">';
})
->rawColumns(['checkbox'])
->make();

}
Expand Down
3 changes: 3 additions & 0 deletions lang/ca/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
'table' => 'Taula',
'chart' => 'Gràfic',
'disk_usage' => 'Ús de disc',
'confirm_changes' => 'Confirma els canvis',
'are_you_sure_to_change_statuses' => 'Esteu segur/a de voler canviar l\'estat dels elements seleccionats?',
'change_statuses' => 'Canvia els estats'
'dashboard' => 'Tauler del centre',
'affected_rows' => 'Files afectades',
];
123 changes: 123 additions & 0 deletions resources/views/admin/batch/instances.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
@extends('layout.default')

@section('content')
<div class="admin-menu-container">
@include('menu.adminmenu')
</div>

<div class="content batch instances">
<h3>{{ __('instance.instance_list') }}</h3>

@include('components.messages')

<div class="mt-3" style="display: flex; margin-bottom: 20px">
<select id="new-status" class="form-control" style="width: auto; margin-right: 10px">
<option value="">{{ __('common.status') }}</option>
@foreach($statusList as $key => $status)
<option value="{{ $key }}">{{ $status }}</option>
@endforeach
</select>
<button id="apply-changes" class="btn btn-primary mt-2">
{{ __('common.change_statuses') }}
</button>
</div>

<table id="instances-table" class="table table-bordered table-hover">
<thead>
<tr>
<th>ID</th>
<th>{{ __('client.name') }}</th>
<th>{{ __('client.dns') }}</th>
<th>{{ __('client.code') }}</th>
<th>{{ __('instance.db_id') }}</th>
<th>{{ __('common.status') }}</th>
<th>{{ __('service.service') }}</th>
<th>
<input type="checkbox" id="select-all">
</th>
</tr>
</thead>
</table>
</div>

<div id="confirmation-modal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{{ __('common.confirm_changes') }}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>{{ __('common.are_you_sure_to_change_statuses') }}</p>
</div>
<div class="modal-footer">
<button type="button" id="confirm-apply" class="btn btn-primary">{{ __('common.yes') }}</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">{{ __('common.no') }}</button>
</div>
</div>
</div>
</div>

<script>
$(document).ready(function() {
let table = $('#instances-table').DataTable({
processing: true,
serverSide: true,
ajax: '{{ route('instances.list') }}',
columns: [
{ data: 'id' },
{ data: 'client_name' },
{ data: 'client_dns' },
{ data: 'client_code' },
{ data: 'db_id' },
{ data: 'status' },
{ data: 'service_id' },
{ data: 'checkbox', orderable: false, searchable: false }
]
});

$('#select-all').on('click', function() {
let rows = table.rows({ 'search': 'applied' }).nodes();
$('input[type="checkbox"]', rows).prop('checked', this.checked);
});

$('#apply-changes').on('click', function() {
let selected = [];
table.$('input[type="checkbox"]:checked').each(function() {
selected.push($(this).data('id'));
});

let newStatus = $('#new-status').val();
if (selected.length && newStatus) {
$('#confirmation-modal').modal('show');
} else {
console.log('{{ __('status.select_instance_and_status') }}');
}

$('#confirm-apply').on('click', function() {
$.ajax({
url: '{{ route("batch.instances.updateStatus") }}',
method: 'POST',
data: {
ids: selected,
status: newStatus,
_token: '{{ csrf_token() }}'
},
success: function(response) {
table.ajax.reload();
$('#confirmation-modal').modal('hide');
$('#select-all').prop('checked', false);
},
error: function() {
console.log('{{ __('common.error_occurred') }}');
console.log(response.message);
}
});
});
});
});
</script>

@endsection
7 changes: 6 additions & 1 deletion resources/views/menu/adminmenu.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,15 @@
</a>
</li>
<li>
<a href="{{ route('batch.instance.create') }}" @if (str_contains(request()->url(), 'instance')) class="selected" @endif>
<a href="{{ route('batch.instance.create') }}" @if (str_contains(request()->url(), 'instance') && !str_contains(request()->url(), 'instances')) class="selected" @endif>
{{ __('batch.batch_creation') }}
</a>
</li>
<li>
<a href="{{ route('batch.instances.list') }}" @if (str_contains(request()->url(), 'instances')) class="selected" @endif>
{{ __('instance.instances') }}
</a>
</li>
</ul>
@endif

Expand Down
4 changes: 4 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@

Route::get('/batch/instance/create', [BatchController::class, 'instanceCreate'])->name('batch.instance.create');
Route::post('/batch/instance', [BatchController::class, 'instanceStore'])->name('batch.instance.store');
Route::get('/batch/instances', [BatchController::class, 'instancesList'])->name('batch.instances.list');
Route::get('/batch/instances/data', [BatchController::class, 'getInstancesData'])->name('batch.instances.data');
Route::post('/batch/instances/update-status', [BatchController::class, 'updateStatus'])->name('batch.instances.updateStatus');

Route::get('/files/{path?}', [DirectoryController::class, 'index'])->name('files.index');
Route::get('/files/download/{path}', [DirectoryController::class, 'download'])->name('files.download');
Route::post('/files/upload/{currentPath}', [DirectoryController::class, 'upload'])->name('files.upload');
Expand Down