From 23f4cb84e6c41e75f5be6e488ae9936259e051b2 Mon Sep 17 00:00:00 2001 From: Farhan Kathawala <37834439+farhaninfyom@users.noreply.github.com> Date: Mon, 2 Sep 2019 19:06:34 +0530 Subject: [PATCH 01/25] test(roles): roles route permissions tests added (#305) --- database/factories/UserFactory.php | 3 + .../RoleControllerPermissionTest.php | 128 ++++++++++++++++++ tests/TestCase.php | 23 ++++ 3 files changed, 154 insertions(+) create mode 100644 tests/Permissiion/RoleControllerPermissionTest.php diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index eee07d140..dce948130 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -22,5 +22,8 @@ 'email_verified_at' => now(), 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 'remember_token' => Str::random(10), + 'is_active' => true, + 'is_email_verified' => true, + 'set_password' => true, ]; }); diff --git a/tests/Permissiion/RoleControllerPermissionTest.php b/tests/Permissiion/RoleControllerPermissionTest.php new file mode 100644 index 000000000..45ba3f9cd --- /dev/null +++ b/tests/Permissiion/RoleControllerPermissionTest.php @@ -0,0 +1,128 @@ +user = factory(User::class)->create(); + $this->actingAs($this->user); + } + + /** + * @test + */ + public function test_can_get_roles_with_valid_permission() + { + $this->attachPermissions($this->user->id, ['manage_roles']); + $response = $this->getJson(route('roles.index')); + + $response->assertStatus(200); + } + + /** + * @test + */ + public function test_not_allow_to_get_roles_without_permission() + { + $response = $this->get(route('roles.index')); + + $response->assertStatus(403); + } + + /** + * @test + */ + public function test_can_create_role_with_valid_permission() + { + $this->attachPermissions($this->user->id, ['manage_roles']); + + $role = factory(Role::class)->raw(); + + $response = $this->postJson(route('roles.store'), $role); + + $response->assertStatus(302); + $response->assertRedirect('roles'); + } + + /** + * @test + */ + public function test_not_allow_to_create_role_without_permission() + { + $role = factory(Role::class)->raw(); + + $response = $this->post(route('roles.store'), $role); + + $response->assertStatus(403); + } + + /** + * @test + */ + public function test_can_update_role_with_valid_permission() + { + $this->attachPermissions($this->user->id, ['manage_roles']); + + /** @var Role $role */ + $role = factory(Role::class)->create(); + $updateRole = factory(Role::class)->raw(['id' => $role->id]); + + $response = $this->putJson(route('roles.update', $role->id), $updateRole); + + $response->assertStatus(302); + $response->assertRedirect('roles'); + } + + /** + * @test + */ + public function test_not_allow_to_update_role_without_permission() + { + /** @var Role $role */ + $role = factory(Role::class)->create(); + $updateRole = factory(Role::class)->raw(['id' => $role->id]); + + $response = $this->put(route('roles.update', $role->id), $updateRole); + + $response->assertStatus(403); + } + + /** + * @test + */ + public function test_can_delete_role_with_valid_permission() + { + $this->attachPermissions($this->user->id, ['manage_roles']); + + /** @var Role $role */ + $role = factory(Role::class)->create(); + + $response = $this->deleteJson(route('roles.destroy', $role->id)); + + $response->assertStatus(200); + } + + /** + * @test + */ + public function test_not_allow_to_delete_role_without_permission() + { + /** @var Role $role */ + $role = factory(Role::class)->create(); + + $response = $this->delete(route('roles.destroy', $role->id)); + + $response->assertStatus(403); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 2b0a3ce7e..af6f26754 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,6 +2,8 @@ namespace Tests; +use App\Models\Permission; +use App\Models\Role; use App\Models\User; use Carbon\Carbon; use Faker\Factory; @@ -78,4 +80,25 @@ protected function mockTime($string, $timezone = 'UTC') return Carbon::now(); } + + /** + * @param array $permissions + * @param int $userId + * + * @return User + */ + public function attachPermissions($userId, $permissions = []) + { + /** @var User $user */ + $user = User::findOrFail($userId); + $permissionIds = Permission::whereIn('name', $permissions)->get()->pluck('id'); + + /** @var Role $role */ + $role = factory(Role::class)->create(); + $role->perms()->sync($permissionIds); + + $user->attachRole($role); + + return $user; + } } From d8d4a254df7d477df13e0599b18a168c58841d59 Mon Sep 17 00:00:00 2001 From: Monika Vaghasiya <51854283+MonikaInfyOm@users.noreply.github.com> Date: Tue, 3 Sep 2019 11:57:11 +0530 Subject: [PATCH 02/25] feat(UI): added focus on first input of model on model open event #301) --- resources/assets/js/custom.js | 13 +++++++++++++ resources/assets/js/report/report.js | 4 ++++ resources/assets/js/users/user.js | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/resources/assets/js/custom.js b/resources/assets/js/custom.js index d1bf03c29..95754fb11 100644 --- a/resources/assets/js/custom.js +++ b/resources/assets/js/custom.js @@ -165,3 +165,16 @@ window.displaySuccessMessage = function (message) { position: 'top-right', }); }; + +//focus on select2 +$(document).on('focus', '.select2-selection.select2-selection--single', function (e) { + $(this).closest(".select2-container").siblings('select:enabled').select2('open'); +}); + +$(function () { + $(".modal").on('shown.bs.modal', function () { + setTimeout(function () { + $(".modal").find('input:text, .select2-selection.select2-selection--single').first().focus(); + },150); + }); +}); diff --git a/resources/assets/js/report/report.js b/resources/assets/js/report/report.js index e2a152a06..dcd8c3509 100644 --- a/resources/assets/js/report/report.js +++ b/resources/assets/js/report/report.js @@ -44,6 +44,10 @@ $('#end_date').datetimepicker({ maxDate: moment() }); +$(function () { + $('form').find('input:text').filter(':input:visible:first').first().focus(); +}); + $("#start_date").on("dp.change", function (e) { $('#end_date').data("DateTimePicker").minDate(e.date); }); diff --git a/resources/assets/js/users/user.js b/resources/assets/js/users/user.js index a6cd92def..0e8bcfb73 100644 --- a/resources/assets/js/users/user.js +++ b/resources/assets/js/users/user.js @@ -4,7 +4,8 @@ $(function () { }); $('#roleId,#editRoleId').select2({ width: '100%', - placeholder: "Select Role" + placeholder: "Select Role", + minimumResultsForSearch: -1 }); }); From 2a8593ee9a753fd1cea498a2bb964dedd98fab0a Mon Sep 17 00:00:00 2001 From: Monika Vaghasiya <51854283+MonikaInfyOm@users.noreply.github.com> Date: Tue, 3 Sep 2019 12:01:31 +0530 Subject: [PATCH 03/25] feat(time-entry): when user open new time entry pop up end will be selected as current date-time (#304) --- resources/assets/js/time_entries/time_entry.js | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/assets/js/time_entries/time_entry.js b/resources/assets/js/time_entries/time_entry.js index 5ad667a39..b93c9f762 100644 --- a/resources/assets/js/time_entries/time_entry.js +++ b/resources/assets/js/time_entries/time_entry.js @@ -261,6 +261,7 @@ $('#startTime,#endTime').on('dp.change', function (selected) { $('#startTime').data("DateTimePicker").maxDate(moment().endOf('now')); $('#endTime').data("DateTimePicker").maxDate(moment().endOf('now')); }); +$('#endTime').val(format(Date(), 'YYYY-MM-DD HH:mm:ss')); $('#editTimeEntryForm').submit(function (event) { event.preventDefault(); From 056fbf85340e5be792fb97ecbb636b6d7e2beaa6 Mon Sep 17 00:00:00 2001 From: Monika Vaghasiya <51854283+MonikaInfyOm@users.noreply.github.com> Date: Tue, 3 Sep 2019 12:28:45 +0530 Subject: [PATCH 04/25] fix(task-detail): any file should be remove from attachment in task detail screen (#311) --- resources/assets/js/task/task_detail.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/resources/assets/js/task/task_detail.js b/resources/assets/js/task/task_detail.js index 84d08c33f..23df41144 100644 --- a/resources/assets/js/task/task_detail.js +++ b/resources/assets/js/task/task_detail.js @@ -239,11 +239,10 @@ Dropzone.options.dropzone = { let newFileName = fileNameExtArr[0]; let newFileExt = fileNameExtArr[1]; let prevFileName = fileuploded.innerHTML.split('.')[0]; - let fileUrl = attachmentUrl + fileName; fileuploded.innerHTML = fileName; - $(".dz-preview:last-child").children(':last-child').attr('data-file-id', attachment.id); - $(".dz-preview:last-child").children(':last-child').attr('data-file-url', attachment.file_url); + $(file.previewTemplate).find('.dz-remove').attr('data-file-id', attachment.id); + $(file.previewTemplate).find('.dz-remove').attr('data-file-url', attachment.file_url); if($.inArray(newFileExt,['jpg','jpge','png']) > -1) { $(".previewEle").find('.' + prevFileName).attr('href', attachment.file_url); $(".previewEle").find('.' + prevFileName).attr('class', newFileName); From 55b5cf72be2a70bd7285750559efce0a014cf69c Mon Sep 17 00:00:00 2001 From: Monika Vaghasiya <51854283+MonikaInfyOm@users.noreply.github.com> Date: Tue, 3 Sep 2019 12:37:58 +0530 Subject: [PATCH 05/25] fix(edit-profile): added password view/block functionality (#312) --- resources/assets/js/profile/profile.js | 14 +++++++++++-- resources/assets/style/sass/style.scss | 8 +++++++- .../views/profile/edit_profile.blade.php | 20 ++++++++++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/resources/assets/js/profile/profile.js b/resources/assets/js/profile/profile.js index a9d83f822..a01fd1513 100644 --- a/resources/assets/js/profile/profile.js +++ b/resources/assets/js/profile/profile.js @@ -4,7 +4,7 @@ $('#editProfileForm').submit(function (event) { if(!isValidate){ return false; } - let loadingButton = jQuery(this).find("#btnEditSave"); + let loadingButton = jQuery(this).find("#btnPrEditSave"); loadingButton.button('loading'); $.ajax({ url: usersUrl + 'profile-update', @@ -120,4 +120,14 @@ function validatePassword() { return false; } return true; -} \ No newline at end of file +} + +$(".changeType").click(function () { + let inputField = $(this).parent().siblings(); + let oldType = inputField.attr('type'); + if(oldType == 'password') { + inputField.attr('type', 'text'); + } else { + inputField.attr('type', 'password'); + } +}); diff --git a/resources/assets/style/sass/style.scss b/resources/assets/style/sass/style.scss index b42637b49..25ef0ac9a 100644 --- a/resources/assets/style/sass/style.scss +++ b/resources/assets/style/sass/style.scss @@ -483,7 +483,7 @@ table.dataTable { } .edit-profile__file-upload { - padding: 10px; + padding: 7px 10px; background: #20a8d8; display: table; color: $white; @@ -550,3 +550,9 @@ table.dataTable { overflow-y: auto; max-height: 750px; } + +.input-group__addon { + border-top-right-radius: 0 !important; + border-bottom-right-radius: 0 !important; +} + diff --git a/resources/views/profile/edit_profile.blade.php b/resources/views/profile/edit_profile.blade.php index e20f4c628..33e8696d0 100644 --- a/resources/views/profile/edit_profile.blade.php +++ b/resources/views/profile/edit_profile.blade.php @@ -43,15 +43,29 @@
{!! Form::label('password', 'New Password') !!}* - {!! Form::text('password', null, ['class' => 'form-control', 'id' => 'pfNewPassword']) !!} +
+ +
+ + + +
+
{!! Form::label('password_confirmation', 'Confirm Password') !!}* - {!! Form::text('password_confirmation', null, ['class' => 'form-control', 'id' => 'pfNewConfirmPassword']) !!} +
+ +
+ + + +
+
- {!! Form::button('Save', ['type'=>'submit','class' => 'btn btn-primary','id'=>'btnEditSave','data-loading-text'=>" Processing..."]) !!} + {!! Form::button('Save', ['type'=>'submit','class' => 'btn btn-primary','id'=>'btnPrEditSave','data-loading-text'=>" Processing..."]) !!} From 2445ca0c19917a0408350d46d0c983425c6d05e6 Mon Sep 17 00:00:00 2001 From: Monika Vaghasiya <51854283+MonikaInfyOm@users.noreply.github.com> Date: Tue, 3 Sep 2019 12:49:35 +0530 Subject: [PATCH 06/25] eat(user): make role field of user add/edit form required (#302) --- app/Http/Requests/UpdateUserRequest.php | 7 ++++--- app/Models/User.php | 14 ++++++++------ resources/views/users/modal.blade.php | 4 ++-- .../Validations/UserControllerValidationTest.php | 10 ++++++---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/Http/Requests/UpdateUserRequest.php b/app/Http/Requests/UpdateUserRequest.php index bc97f78cc..d95cba607 100644 --- a/app/Http/Requests/UpdateUserRequest.php +++ b/app/Http/Requests/UpdateUserRequest.php @@ -34,9 +34,10 @@ public function rules() { $id = $this->route('user')->id; $rules = [ - 'name' => 'required|unique:users,name,'.$id, - 'email' => 'required|email|unique:users,email,'.$id.'|regex:/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/', - 'phone' => 'nullable|numeric|digits:10', + 'name' => 'required|unique:users,name,'.$id, + 'email' => 'required|email|unique:users,email,'.$id.'|regex:/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/', + 'phone' => 'nullable|numeric|digits:10', + 'role_id' => 'required', ]; return $rules; diff --git a/app/Models/User.php b/app/Models/User.php index db381f64d..84bde1672 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -112,15 +112,17 @@ class User extends Authenticatable * @var array */ public static $rules = [ - 'name' => 'required|unique:users,name', - 'email' => 'required|email|unique:users,email|regex:/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/', - 'phone' => 'nullable|numeric|digits:10', + 'name' => 'required|unique:users,name', + 'email' => 'required|email|unique:users,email|regex:/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/', + 'phone' => 'nullable|numeric|digits:10', + 'role_id' => 'required', ]; public static $messages = [ - 'phone.digits' => 'The phone number must be 10 digits long.', - 'email.regex' => 'Please enter valid email.', - 'photo.mimes' => 'The profile image must be a file of type: jpeg, jpg, png.', + 'phone.digits' => 'The phone number must be 10 digits long.', + 'email.regex' => 'Please enter valid email.', + 'photo.mimes' => 'The profile image must be a file of type: jpeg, jpg, png.', + 'role_id.required' => 'Please select user role.', ]; public static $setPasswordRules = [ diff --git a/resources/views/users/modal.blade.php b/resources/views/users/modal.blade.php index aeb3e4309..9f7ec7553 100644 --- a/resources/views/users/modal.blade.php +++ b/resources/views/users/modal.blade.php @@ -35,8 +35,8 @@
- {!! Form::label('role_id', 'Role') !!} - {!! Form::select('role_id', $roles, null, ['class' => 'form-control', 'id' => 'roleId','placeholder'=>'Select Role']) !!} + {!! Form::label('role_id', 'Role') !!}* + {!! Form::select('role_id', $roles, null, ['class' => 'form-control', 'id' => 'roleId','placeholder'=>'Select Role', 'required']) !!}
diff --git a/tests/Controllers/Validations/UserControllerValidationTest.php b/tests/Controllers/Validations/UserControllerValidationTest.php index 4bbfd3c93..967b870c3 100644 --- a/tests/Controllers/Validations/UserControllerValidationTest.php +++ b/tests/Controllers/Validations/UserControllerValidationTest.php @@ -59,8 +59,9 @@ public function test_create_user_fails_when_email_is_invalid() public function it_can_create_user() { $input = [ - 'name' => 'random string', - 'email' => 'dummy@gmail.com', + 'name' => 'random string', + 'email' => 'dummy@gmail.com', + 'role_id' => 1, ]; $this->post(route('users.store'), $input)->assertSessionHasNoErrors(); @@ -129,8 +130,9 @@ public function it_can_update_user_with_valid_input() /** @var User $user */ $user = factory(User::class)->create(); $input = [ - 'name' => 'random string', - 'email' => 'dummy@gmail.com', + 'name' => 'random string', + 'email' => 'dummy@gmail.com', + 'role_id' => 1, ]; $this->put(route('users.update', $user->id), $input)->assertSessionHasNoErrors(); From 5f9bdaf5abf5a51b59bc2607c6ef5527dc1a83e4 Mon Sep 17 00:00:00 2001 From: Monika vaghasiya Date: Tue, 3 Sep 2019 12:50:33 +0530 Subject: [PATCH 07/25] fix(role): added focus on first element in roles screen --- resources/views/roles/create.blade.php | 2 ++ resources/views/roles/edit.blade.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/resources/views/roles/create.blade.php b/resources/views/roles/create.blade.php index 9a25551f0..c23209f1b 100644 --- a/resources/views/roles/create.blade.php +++ b/resources/views/roles/create.blade.php @@ -36,6 +36,8 @@ checkboxClass: 'icheckbox_flat-blue', increaseArea: '10%' }); + + $('form').find('input:text').filter(':input:visible:first').first().focus(); }); @endsection diff --git a/resources/views/roles/edit.blade.php b/resources/views/roles/edit.blade.php index 7a15dda4a..1484b58d7 100644 --- a/resources/views/roles/edit.blade.php +++ b/resources/views/roles/edit.blade.php @@ -36,6 +36,8 @@ checkboxClass: 'icheckbox_flat-blue', increaseArea: '10%' }); + + $('form').find('input:text').filter(':input:visible:first').first().focus(); }); @endsection \ No newline at end of file From f538b2a670a2c29c704dd2c10cd8fff31c8dc112 Mon Sep 17 00:00:00 2001 From: Monika vaghasiya Date: Tue, 3 Sep 2019 12:56:43 +0530 Subject: [PATCH 08/25] fix(client): chnage cancel button id in edit pop up --- resources/views/clients/edit_modal.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/clients/edit_modal.blade.php b/resources/views/clients/edit_modal.blade.php index bd16a2ac6..f8830c561 100644 --- a/resources/views/clients/edit_modal.blade.php +++ b/resources/views/clients/edit_modal.blade.php @@ -30,7 +30,7 @@
{!! Form::button('Save', ['type'=>'submit','class' => 'btn btn-primary','id'=>'btnEditSave','data-loading-text'=>" Processing..."]) !!} - +
{!! Form::close() !!} From c34d78f69d919c547f08d3951d0b813513cbee4f Mon Sep 17 00:00:00 2001 From: Monika vaghasiya Date: Tue, 3 Sep 2019 12:57:55 +0530 Subject: [PATCH 09/25] Revert "fix(client): chnage cancel button id in edit pop up" This reverts commit f538b2a670a2c29c704dd2c10cd8fff31c8dc112. --- resources/views/clients/edit_modal.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/clients/edit_modal.blade.php b/resources/views/clients/edit_modal.blade.php index f8830c561..bd16a2ac6 100644 --- a/resources/views/clients/edit_modal.blade.php +++ b/resources/views/clients/edit_modal.blade.php @@ -30,7 +30,7 @@
{!! Form::button('Save', ['type'=>'submit','class' => 'btn btn-primary','id'=>'btnEditSave','data-loading-text'=>" Processing..."]) !!} - +
{!! Form::close() !!} From 0b41507dea2bb7955fa70d62fd4757971ea3ff9f Mon Sep 17 00:00:00 2001 From: Monika Vaghasiya <51854283+MonikaInfyOm@users.noreply.github.com> Date: Tue, 3 Sep 2019 14:09:39 +0530 Subject: [PATCH 10/25] =?UTF-8?q?fix(UI):=20remove=20pagination=20icons=20?= =?UTF-8?q?if=20there=20is=20only=20one=20page=20in=20datatab=E2=80=A6=20(?= =?UTF-8?q?#308)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/js/custom.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/resources/assets/js/custom.js b/resources/assets/js/custom.js index 95754fb11..35922a485 100644 --- a/resources/assets/js/custom.js +++ b/resources/assets/js/custom.js @@ -166,6 +166,22 @@ window.displaySuccessMessage = function (message) { }); }; +$(function () { + $(".dataTables_length").css('padding-top', '6px'); + $(".dataTables_info").css('padding-top', '24px'); +}); + +$.extend($.fn.dataTable.defaults, { + drawCallback: function (settings) { + let thisTableId = settings.sTableId; + if (settings.fnRecordsDisplay() > settings._iDisplayLength) { + $('#' + thisTableId + '_paginate').show(); + } else { + $('#' + thisTableId + '_paginate').hide(); + } + } +}); + //focus on select2 $(document).on('focus', '.select2-selection.select2-selection--single', function (e) { $(this).closest(".select2-container").siblings('select:enabled').select2('open'); From cb9af332ec3d90b5e48101abe7d2242b442eaa62 Mon Sep 17 00:00:00 2001 From: Monika Vaghasiya <51854283+MonikaInfyOm@users.noreply.github.com> Date: Tue, 3 Sep 2019 14:20:04 +0530 Subject: [PATCH 11/25] feat(time-entry): if time entry geater than 12 hr then allow user to adjust start time and make time entry less than 12 hr (#307) --- .../assets/js/time_tracker/time_tracker.js | 96 ++++++++++++++++++- resources/views/layouts/app.blade.php | 6 ++ resources/views/time_entries/index.blade.php | 9 -- .../time_tracker/adjust_time_entry.blade.php | 40 ++++++++ 4 files changed, 140 insertions(+), 11 deletions(-) create mode 100644 resources/views/time_tracker/adjust_time_entry.blade.php diff --git a/resources/assets/js/time_tracker/time_tracker.js b/resources/assets/js/time_tracker/time_tracker.js index 05fe3b4eb..d676bb53e 100644 --- a/resources/assets/js/time_tracker/time_tracker.js +++ b/resources/assets/js/time_tracker/time_tracker.js @@ -191,7 +191,7 @@ $("#stopTimer").click(function (e) { enableTimerData(); $('#loader').show(); - storeTimeEntry(); + checkTimeEntry(); }); function enableTimerData() { @@ -215,10 +215,102 @@ function stopTime() { seconds = minutes = hours = 0; } -function storeTimeEntry() { +function diff_mins(dt2, dt1) { + dt2 = new Date(dt2); + dt1 = new Date(dt1); + var diff = (dt2.getTime() - dt1.getTime()) / 1000; + diff /= (60); + return Math.abs(Math.round(diff)); +} + +function adjustTimeEntry() { + let startDate = getItemFromLocalStorage('start_time'); + $("#tmAdjustValidationErrorsBox").show(); + $("#tmAdjustValidationErrorsBox").html("Time Entry must be less than 12 hours."); + $('#adjustStartTime').val(startDate); + $('#adjustStartTime').attr('disabled', 'true'); + $("#timeEntryAdjustModal").modal(); + $('#stopTimer').removeAttr('disabled'); +} + +$('#timeEntryAdjustModal').on('hidden.bs.modal', function () { + $('#adjustEndTime').prop('disabled', false); + $('#adjustStartTime').prop('disabled', false); + $("#adjustEndTime").data("DateTimePicker").date(null); + $("#adjustStartTime").data("DateTimePicker").date(null); + resetModalForm('#timeEntryAdjustForm'); + $('#tmAdjustValidationErrorsBox').hide(); +}); + +$('#adjustStartTime').datetimepicker({ + format: 'YYYY-MM-DD HH:mm:ss', + useCurrent: true, + icons: { + up: "icon-arrow-up icons", + down: "icon-arrow-down icons", + previous: 'icon-arrow-left icons', + next: 'icon-arrow-right icons', + }, + sideBySide: true, + maxDate: moment().endOf('day'), +}); +$('#adjustEndTime').datetimepicker({ + format: 'YYYY-MM-DD HH:mm:ss', + useCurrent: true, + icons: { + up: "icon-arrow-up icons", + down: "icon-arrow-down icons", + previous: 'icon-arrow-left icons', + next: 'icon-arrow-right icons', + }, + sideBySide: true, + maxDate: moment().endOf('day'), +}); + +$('#adjustStartTime,#adjustEndTime').on('dp.change', function () { + const startTime = $('#adjustStartTime').val(); + const endTime = $('#adjustEndTime').val(); + let minutes = 0; + if (endTime) { + const diff = new Date(Date.parse(endTime) - Date.parse(startTime)); + minutes = diff / (1000 * 60); + if (!Number.isInteger(minutes)) { + minutes = minutes.toFixed(2); + } + } + $('#adjustDuration').val(minutes).prop('disabled', true); + $('#adjustStartTime').data("DateTimePicker").maxDate(moment().endOf('now')); + $('#adjustEndTime').data("DateTimePicker").maxDate(moment().endOf('now')); + if(minutes < 720) { + $('#tmAdjustValidationErrorsBox').hide(); + } +}); + +$('#adjustBtnSave').click(function () { + let startTime = $('#adjustStartTime').val(); + let endTime = $('#adjustEndTime').val(); + let totalMin = diff_mins(endTime, startTime); + if(totalMin > 720) { + $("#tmAdjustValidationErrorsBox").show(); + $("#tmAdjustValidationErrorsBox").html("Time Entry must be less than 12 hours."); + } else { + $("#adjustBtnCancel").trigger('click'); + storeTimeEntry(startTime, endTime); + } +}); + +function checkTimeEntry() { let startTime = getItemFromLocalStorage('start_time'); let endTime = getCurrentTime(); + let totalMin = diff_mins(endTime, startTime); + if(totalMin > 720) { + adjustTimeEntry(); + } else { + storeTimeEntry(startTime, endTime); + } +} +function storeTimeEntry(startTime, endTime) { $.ajax({ url: storeTimeEntriesUrl, type: 'POST', diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index c675b5982..115ba2719 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -18,6 +18,10 @@ + + @yield('page_css') @yield('css') @@ -70,6 +74,7 @@ @include('time_tracker.index'); +@include('time_tracker.adjust_time_entry');