Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #214 from InfyOmLabs/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mitulgolakiya authored Aug 3, 2019
2 parents 178f30a + da3d30f commit 5f7eed6
Show file tree
Hide file tree
Showing 33 changed files with 1,086 additions and 53 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
language: php
php:
- '7.1'
- '7.2'
- '7.3'
- '7.1'
- '7.2'
- '7.3'
sudo: false
install: travis_retry composer install --no-interaction --prefer-dist
script: vendor/bin/phpunit --verbose
notifications:
slack:
rooms:
secure: EhuD5CbAzJECUUdCwmcTH4JBpXojl3fbiPlf2Psx7Lf0jct75HF0O7/6Zp0ury5l0j3FU/lQkQBV8AYqbUk9hESh6iC1q+pmqN1q0TV89WdVdkujHPW0LZ67ucq78D6757XM2AR/lDAKjt18yMk4Inv25kUYXvonFqdcRrW8H2wQRI7n0qZRGHv2fOp23/ZtC1tq7tLguBF7hqq477Ku72BdRBKdrzBcJrZUsmAzWJjCkBFeCPPcpeBtZiJ9iDohY8SYFC8XPG0Hm0Taq100VRnex18z02GhqrXYGmaAoPX2LP9aF5iOFUjmYD4gN8wFiOpH+WCKb73B89jgbosA6Ik/xl7ahefHLb5IgG0O6TO1MbmncKO9iE39ZmugcUNjPOYemwX44LfA3RRyTTwcUbCQI4HEgSmTeU7d/ViH5vr+Zyt2I3w9Lw4OAmRzcJ5CRKMAIB+xHS9k1s4bZyT8qF56fUpPnB2r3lHIFZjXG8BsxiuxRQPQ34qjNHhMX0+dymMoO8q7oGQd5FQqtFyCgYscL+yysUh3xZn4OFBtsj2ucGq3/w5WBUF/36UAXEGin4NLkCAd159CBrvUk2FSirbyz4N4kougo28bR08dj2nyiF44vwg21g599rbaKDUZov+L6rVEQ2ybVHDKdr5n/PkV8YDFM+v8uCFFfAjsHZo=
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LoginController extends Controller
*
* @var string
*/
protected $redirectTo = '/tasks';
protected $redirectTo = '/home';

/**
* Create a new controller instance.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RegisterController extends Controller
*
* @var string
*/
protected $redirectTo = '/tasks';
protected $redirectTo = '/home';

/**
* Create a new controller instance.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ResetPasswordController extends Controller
*
* @var string
*/
protected $redirectTo = '/tasks';
protected $redirectTo = '/home';

/**
* Create a new controller instance.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/VerificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class VerificationController extends Controller
*
* @var string
*/
protected $redirectTo = '/tasks';
protected $redirectTo = '/home';

/**
* Create a new controller instance.
Expand Down
14 changes: 12 additions & 2 deletions app/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public function store(CreateTaskRequest $request)
{
$input = $request->all();
/** @var Task $task */
$indexNumber = $this->taskRepository->getIndex($input['project_id']);
$input['task_number'] = $indexNumber;
$uniqueTaskNumber = $this->taskRepository->getUniqueTaskNumber($input['project_id']);
$input['task_number'] = $uniqueTaskNumber;
$this->taskRepository->store($this->fill($input));

return $this->sendSuccess('Task created successfully.');
Expand Down Expand Up @@ -272,4 +272,14 @@ public function getAttachment(Task $task)

return $this->sendResponse($result, 'Task retrieved successfully.');
}

/**
* @param Task $task
*
* @return JsonResponse
*/
public function getCommentsCount(Task $task)
{
return $this->sendResponse($task->comments()->count(), 'Comments count retrieved successfully.');
}
}
8 changes: 5 additions & 3 deletions app/Http/Controllers/TimeEntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function index(Request $request)
{
if ($request->ajax()) {
return Datatables::of((new TimeEntryDataTable())->get(
$request->only('filter_activity', 'filter_user'))
$request->only('filter_activity', 'filter_user', 'filter_project'))
)->make(true);
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public function update(TimeEntry $timeEntry, UpdateTimeEntryRequest $request)
if (empty($entry)) {
return $this->sendError('Time Entry not found.', Response::HTTP_NOT_FOUND);
}
$input = $this->validateInput($request->all());
$input = $this->validateInput($request->all(), $timeEntry->id);
$existEntry = $entry->only([
'id',
'task_id',
Expand Down Expand Up @@ -139,7 +139,7 @@ public function destroy(TimeEntry $timeEntry)
*
* @return array|\Illuminate\Http\JsonResponse
*/
public function validateInput($input)
public function validateInput($input, $id = null)
{
$startTime = Carbon::parse($input['start_time']);
$endTime = Carbon::parse($input['end_time']);
Expand All @@ -165,6 +165,8 @@ public function validateInput($input)
throw new BadRequestHttpException('Minimum Entry time should be 1 minute.');
}

$this->timeEntryRepository->checkDuplicateEntry($input, $id);

$input['user_id'] = getLoggedInUserId();
if (!isset($input['note']) || empty($input['note'])) {
$input['note'] = 'N/A';
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RedirectIfAuthenticated
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/tasks');
return redirect('/home');
}

return $next($request);
Expand Down
3 changes: 2 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @property string|null $phone
* @property \Illuminate\Support\Carbon|null $email_verified_at
* @property string|null $password
* @property int $set_password
* @property bool $set_password
* @property int $is_email_verified
* @property int $is_active
* @property string|null $activation_code
Expand Down Expand Up @@ -95,6 +95,7 @@ class User extends Authenticatable
*/
protected $casts = [
'email_verified_at' => 'datetime',
'set_password' => 'boolean',
];

/**
Expand Down
12 changes: 12 additions & 0 deletions app/Queries/TimeEntryDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Queries;

use App\Models\Task;
use App\Models\TimeEntry;
use App\Models\User;
use Auth;
Expand Down Expand Up @@ -36,6 +37,17 @@ function (Builder $q) use ($input) {
function (Builder $q) use ($input) {
$q->where('user_id', $input['filter_user']);
});
$query->when(isset($input['filter_project']) && !empty($input['filter_project']),
function (Builder $q) use ($input) {
$taskIds = Task::whereProjectId($input['filter_project'])
->where('status', '=', Task::STATUS_ACTIVE)
->where(function ($q) {
$q->whereHas('taskAssignee', function ($q) {
$q->where('user_id', getLoggedInUser()->id);
});
})->get()->pluck('id')->toArray();
$q->whereIn('task_id', $taskIds);
});

return $query;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Repositories/ReportRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public function getDurationTime($minutes)
}

$hour = floor($minutes / 60);
$min = $minutes - $hour * 60;
$min = (int) ($minutes - $hour * 60);
if ($min === 0) {
return $hour.' hr';
}
Expand Down
15 changes: 9 additions & 6 deletions app/Repositories/TaskRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\ActivityType;
use App\Models\Comment;
use App\Models\Project;
use App\Models\Tag;
use App\Models\Task;
use App\Models\TaskAttachment;
Expand Down Expand Up @@ -134,6 +135,8 @@ public function update($input, $id)
*/
public function validateTaskData($input, $task = null)
{
Project::findOrFail($input['project_id']);

if (!empty($task) && $input['due_date'] == $task->due_date) {
return true;
}
Expand Down Expand Up @@ -172,7 +175,7 @@ public function getTaskData()
$data['status'] = $statusArr;
unset($statusArr[Task::STATUS_ALL]);
$data['taskStatus'] = $statusArr;
$data['tasks'] = $this->getTaskList($loginUserProjects);
$data['tasks'] = $this->getTaskList(array_keys($loginUserProjects));
$data['priority'] = Task::PRIORITY;
$data['taskBadges'] = $this->getStatusBadge();

Expand All @@ -191,15 +194,15 @@ public function getStatusBadge()
}

/**
* @param $loginUserProjects
* @param array $projectIds
*
* @return mixed
*/
public function getTaskList($loginUserProjects = [])
public function getTaskList($projectIds = [])
{
$query = Task::orderBy('title');
if (!empty($loginUserProjects)) {
$query = $query->whereIn('project_id', array_keys($loginUserProjects));
if (!empty($projectIds)) {
$query = $query->whereIn('project_id', $projectIds);
}

return $query->pluck('title', 'id');
Expand Down Expand Up @@ -298,7 +301,7 @@ public function myTasks($input = [])
*
* @return int|string|null
*/
public function getIndex($projectId)
public function getUniqueTaskNumber($projectId)
{
/** @var Task $task */
$task = Task::withTrashed()->ofProject($projectId)->where('task_number', '!=',
Expand Down
24 changes: 24 additions & 0 deletions app/Repositories/TimeEntryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\TimeEntry;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;

/**
* Class TimeEntryRepository.
Expand Down Expand Up @@ -144,4 +145,27 @@ public function updateTimeEntry($input, $id)

return true;
}

/**
* @param $input
* @param null $id
*/
public function checkDuplicateEntry($input, $id = null)
{
$timeArr = [$input['start_time'], $input['end_time']];
$query = TimeEntry::where(function ($q) use ($timeArr) {
$q->whereBetween('start_time', $timeArr)
->orWhereBetween('end_time', $timeArr);
})
->orWhereRaw("('$timeArr[0]' between start_time and end_time or '$timeArr[1]' between start_time and end_time)");

if (!empty($id) && $id > 0) {
$query->where('id', '!=', $id);
}

$timeEntry = $query->first();
if (!empty($timeEntry)) {
throw new BadRequestHttpException('Time entry between this duration already exist.');
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "infyomlabs/infy-tracker",
"type": "project",
"version": "1.5.2-alpha",
"version": "1.5.3-alpha",
"description": "Create Projects / Tasks, Track Time, Show Daily Reports",
"keywords": [
"time",
Expand Down
3 changes: 2 additions & 1 deletion database/factories/TagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
/* @var $factory \Illuminate\Database\Eloquent\Factory */

use App\Models\Tag;
use App\Models\User;
use Faker\Generator as Faker;

$factory->define(Tag::class, function (Faker $faker) {
$user = factory(\App\Models\User::class)->create();
$user = factory(User::class)->create();

return [
'name' => $faker->name,
Expand Down
23 changes: 21 additions & 2 deletions database/factories/TaskFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,36 @@

/* @var $factory \Illuminate\Database\Eloquent\Factory */

use App\Models\Project;
use App\Models\Tag;
use App\Models\Task;
use App\Models\User;
use Faker\Generator as Faker;

$factory->define(Task::class, function (Faker $faker) {
$project = factory(\App\Models\Project::class)->create();
$project = factory(Project::class)->create();

return [
'title' => $faker->sentence,
'description' => $faker->sentence,
'project_id' => $project->id,
'due_date' => $faker->dateTime,
'task_number' => $faker->randomDigit,
'task_number' => $faker->unique()->randomDigitNotNull,
];
});

$factory->state(Task::class, 'tag', function () {
$tag = factory(Tag::class)->create();

return [
'tags' => [$tag->id],
];
});

$factory->state(Task::class, 'assignees', function () {
$assignees = factory(User::class)->times(2)->create();

return [
'assignees' => [$assignees[0]->id, $assignees[1]->id],
];
});
10 changes: 10 additions & 0 deletions resources/assets/js/task/task_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ $(document).on('click', '.del-comment', function (event) {
type: 'success',
timer: 2000
});

$.ajax({
url: baseUrl + 'tasks/' + taskId + '/comments-count',
type: 'GET',
success: function (result) {
if (result.data == 0) {
$('.no_comments').show();
}
},
});
},
error: function (data) {
swal({
Expand Down
8 changes: 6 additions & 2 deletions resources/assets/js/time_entries/time_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $('#timeProjectId,#editTimeProjectId').select2({
placeholder: "Select Project"
});

$('#filterActivity,#filterUser').select2({
$('#filterActivity,#filterUser,#filter_project').select2({
minimumResultsForSearch: -1
});

Expand All @@ -28,6 +28,7 @@ let tbl = $('#timeEntryTable').DataTable({
ajax: {
url: timeEntryUrl,
data: function (data) {
data.filter_project = $('#filter_project').find('option:selected').val();
data.filter_activity = $('#filterActivity').find('option:selected').val();
data.filter_user = $('#filterUser').find('option:selected').val();
}
Expand Down Expand Up @@ -114,7 +115,7 @@ let tbl = $('#timeEntryTable').DataTable({
},
],
"fnInitComplete": function () {
$('#filterActivity,#filterUser,#filterTask').change(function () {
$('#filterActivity,#filterUser,#filterTask,#filter_project').change(function () {
tbl.ajax.reload();
});
}
Expand Down Expand Up @@ -193,6 +194,9 @@ $('#editStartTime,#editEndTime').on('dp.change', function () {
if (endTime) {
const diff = new Date(Date.parse(endTime) - Date.parse(startTime));
minutes = diff / (1000 * 60);
if (!Number.isInteger(minutes)) {
minutes = minutes.toFixed(2);
}
}
$('#editDuration').val(minutes).prop('disabled', true);
});
Expand Down
4 changes: 4 additions & 0 deletions resources/views/time_entries/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
{!!Form::select('drp_user',$users,Auth::id(),['id'=>'filterUser','class'=>'form-control','style'=>'min-width:150px;hight:35', 'placeholder' => 'All']) !!}
</div>
@endpermission
<div class="mr-2">
<label class="lbl-block"><b>Project</b></label>
{!!Form::select('drp_project',$projects,null,['id'=>'filter_project','class'=>'form-control','style'=>'min-width:150px;', 'placeholder' => 'All']) !!}
</div>
<div class="mr-2">
<label for="projects" class="lbl-block"><b>Activity Type</b></label>
{!!Form::select('drp_activity',$activityTypes,null,['id'=>'filterActivity','class'=>'form-control','style'=>'min-width:150px;hight:35', 'placeholder' => 'All']) !!}
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
Route::post('tasks/{task}/comments/{comment}/update', 'CommentController@editComment');
Route::delete('tasks/{task}/comments/{comment}', 'CommentController@deleteComment');
Route::get('task-details/{task}', 'TaskController@getTaskDetails');
Route::get('tasks/{task}/comments-count', 'TaskController@getCommentsCount');
});

Route::resource('time-entries', 'TimeEntryController');
Expand Down
Loading

0 comments on commit 5f7eed6

Please sign in to comment.