update cache and UI
This commit is contained in:
parent
d2f5273703
commit
7622e7a95b
|
|
@ -72,6 +72,7 @@ class LeaveManagementController extends Controller
|
||||||
'users.id as user_id',
|
'users.id as user_id',
|
||||||
'users.name as user_name',
|
'users.name as user_name',
|
||||||
'users.email',
|
'users.email',
|
||||||
|
'users.avatar',
|
||||||
'users.created_at as user_created_at',
|
'users.created_at as user_created_at',
|
||||||
'users.permission',
|
'users.permission',
|
||||||
'users.updated_at as user_updated_at',
|
'users.updated_at as user_updated_at',
|
||||||
|
|
@ -92,6 +93,7 @@ class LeaveManagementController extends Controller
|
||||||
'id' => $item->user_id,
|
'id' => $item->user_id,
|
||||||
'name' => $item->user_name,
|
'name' => $item->user_name,
|
||||||
'email' => $item->email,
|
'email' => $item->email,
|
||||||
|
'avatar' => $item->avatar,
|
||||||
'created_at' => $item->user_created_at,
|
'created_at' => $item->user_created_at,
|
||||||
'permission' => $item->permission,
|
'permission' => $item->permission,
|
||||||
'updated_at' => $item->user_updated_at,
|
'updated_at' => $item->user_updated_at,
|
||||||
|
|
|
||||||
|
|
@ -33,24 +33,24 @@ class TimekeepingController extends Controller
|
||||||
$cacheData = CurrentMonthTimekeeping::getCacheCurrentMonthTimekeeping();
|
$cacheData = CurrentMonthTimekeeping::getCacheCurrentMonthTimekeeping();
|
||||||
if ($cacheData) {
|
if ($cacheData) {
|
||||||
$cacheData->data = json_decode($cacheData->data, true);
|
$cacheData->data = json_decode($cacheData->data, true);
|
||||||
return response()->json(['status' => true, 'data' => $cacheData->data, 'working_days' => $cacheData->working_days, 'message' => 'Get from cache']);
|
return response()->json(['status' => true, 'data' => $this->appendUsersInformation($cacheData->data), 'working_days' => $cacheData->working_days, 'message' => 'Get from cache']);
|
||||||
} else {
|
} else {
|
||||||
$result = $this->analyzeCurrentMonthTimeKeepingData($currentMonth, $currentYear);
|
$result = $this->analyzeCurrentMonthTimeKeepingData($currentMonth, $currentYear);
|
||||||
if ($data) {
|
if ($data) {
|
||||||
$data->update(['data' => json_encode($result)]);
|
$data->update(['data' => json_encode($result)]);
|
||||||
return response()->json(['status' => true, 'data' => $result, 'message' => 'Get from analyzeCurrentMonthTimeKeepingData + update record']);
|
return response()->json(['status' => true, 'data' => $this->appendUsersInformation($result), 'message' => 'Get from analyzeCurrentMonthTimeKeepingData + update record']);
|
||||||
}
|
}
|
||||||
MonthlyTimekeeping::create(['month' => $currentMonth, 'year' => $currentYear, 'working_days' => $currentDate->daysInMonth, 'data' => json_encode($result)]);
|
MonthlyTimekeeping::create(['month' => $currentMonth, 'year' => $currentYear, 'working_days' => $currentDate->daysInMonth, 'data' => json_encode($result)]);
|
||||||
return response()->json(['status' => true, 'data' => $result, 'message' => 'Get from analyzeCurrentMonthTimeKeepingData + create record']);
|
return response()->json(['status' => true, 'data' => $this->appendUsersInformation($result), 'message' => 'Get from analyzeCurrentMonthTimeKeepingData + create record']);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($data) {
|
if ($data) {
|
||||||
$data['data'] = json_decode($data['data']);
|
$data['data'] = json_decode($data['data']);
|
||||||
return response()->json(['status' => true, 'data' => $data['data'], 'working_days' => $data['working_days'], 'message' => 'Get from DB']);
|
return response()->json(['status' => true, 'data' => $this->appendUsersInformation($data['data']), 'working_days' => $data['working_days'], 'message' => 'Get from DB']);
|
||||||
} else {
|
} else {
|
||||||
$result = $this->analyzeCurrentMonthTimeKeepingData($request->month, $request->year);
|
$result = $this->analyzeCurrentMonthTimeKeepingData($request->month, $request->year);
|
||||||
MonthlyTimekeeping::create(['month' => $request->month, 'year' => $request->year, 'working_days' => Carbon::create((int)$request->year, (int)$request->month)->daysInMonth, 'data' => json_encode($result)]);
|
MonthlyTimekeeping::create(['month' => $request->month, 'year' => $request->year, 'working_days' => Carbon::create((int)$request->year, (int)$request->month)->daysInMonth, 'data' => json_encode($result)]);
|
||||||
return response()->json(['status' => true, 'data' => $result, 'message' => 'Get from analyzeCurrentMonthTimeKeepingData']);
|
return response()->json(['status' => true, 'data' => $this->appendUsersInformation($result), 'message' => 'Get from analyzeCurrentMonthTimeKeepingData']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return response()->json(['status' => false, 'mewssage' => 'Get data failed!']);
|
return response()->json(['status' => false, 'mewssage' => 'Get data failed!']);
|
||||||
|
|
|
||||||
|
|
@ -54,45 +54,49 @@ class UserController extends Controller
|
||||||
'url' => 'https://ms.prology.net'
|
'url' => 'https://ms.prology.net'
|
||||||
];
|
];
|
||||||
|
|
||||||
$gitea = Http::withHeaders([
|
if (env('APP_ENV') == 'prod' || env('APP_ENV') == 'production') {
|
||||||
'Authorization' => 'token ' . env('GITEA_ADMIN_TOKEN'),
|
$gitea = Http::withHeaders([
|
||||||
'Accept' => 'application/json',
|
'Authorization' => 'token ' . env('GITEA_ADMIN_TOKEN'),
|
||||||
])->post('https://gitea.nswteam.net/api/v1/admin/users', [
|
'Accept' => 'application/json',
|
||||||
'email' => $request->email,
|
])->post('https://gitea.nswteam.net/api/v1/admin/users', [
|
||||||
'full_name' => $request->name,
|
'email' => $request->email,
|
||||||
'login_name' => Str::of($request->name)->lower()->replace(' ', ''),
|
'full_name' => $request->name,
|
||||||
'password' => 'Work@1234',
|
'login_name' => Str::of($request->name)->lower()->replace(' ', ''),
|
||||||
'must_change_password' => false,
|
'password' => 'Work@1234',
|
||||||
'send_notify' => false,
|
'must_change_password' => false,
|
||||||
'username' => Str::of($request->name)->lower()->replace(' ', '')
|
'send_notify' => false,
|
||||||
]);
|
'username' => Str::of($request->name)->lower()->replace(' ', '')
|
||||||
|
]);
|
||||||
|
|
||||||
$gitea_data = $gitea->json();
|
$gitea_data = $gitea->json();
|
||||||
|
|
||||||
$gitea_res = [
|
$gitea_res = [
|
||||||
"login" => $gitea_data['login'],
|
"login" => $gitea_data['login'],
|
||||||
"full_name" => $gitea_data['full_name'],
|
"full_name" => $gitea_data['full_name'],
|
||||||
"email" => $gitea_data['email'],
|
"email" => $gitea_data['email'],
|
||||||
"password" => 'Work@1234',
|
"password" => 'Work@1234',
|
||||||
"url" => 'https://gitea.nswteam.net',
|
"url" => 'https://gitea.nswteam.net',
|
||||||
];
|
];
|
||||||
|
|
||||||
$adminEmail = env('ZULIP_ADMIN_EMAIL');
|
$adminEmail = env('ZULIP_ADMIN_EMAIL');
|
||||||
$apiKey = env('ZULIP_API_KEY');
|
$apiKey = env('ZULIP_API_KEY');
|
||||||
$apiUrl = env('ZULIP_API_URL') . '/invites';
|
$apiUrl = env('ZULIP_API_URL') . '/invites';
|
||||||
|
|
||||||
$zulip = Http::asForm()->withBasicAuth($adminEmail, $apiKey)->post($apiUrl, [
|
$zulip = Http::asForm()->withBasicAuth($adminEmail, $apiKey)->post($apiUrl, [
|
||||||
'invitee_emails' => $request->email,
|
'invitee_emails' => $request->email,
|
||||||
'invite_expires_in_minutes' => 1440,
|
'invite_expires_in_minutes' => 1440,
|
||||||
'invite_as' => 400,
|
'invite_as' => 400,
|
||||||
'stream_ids' => '[22]'
|
'stream_ids' => '[22]'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$zulip_data = $zulip->json();
|
$zulip_data = $zulip->json();
|
||||||
$zulip_data['msg'] = 'Check inbox email ' . $request->email;
|
$zulip_data['msg'] = 'Check inbox email ' . $request->email;
|
||||||
$zulip_data['url'] = 'https://zulip.ipsupply.com.au';
|
$zulip_data['url'] = 'https://zulip.ipsupply.com.au';
|
||||||
|
|
||||||
return response()->json(['data' => ['user' => $user_res, 'gitea' => $gitea_res, 'zulip' => $zulip_data], 'status' => true, 'message' => 'Create successful']);
|
return response()->json(['data' => ['user' => $user_res, 'gitea' => $gitea_res, 'zulip' => $zulip_data], 'status' => true, 'message' => 'Create successful']);
|
||||||
|
} else {
|
||||||
|
return response()->json(['data' => ['user' => $user_res, 'gitea' => "dev", 'zulip' => "dev"], 'status' => true, 'message' => 'Create successful']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(['status' => false, 'message' => 'Process fail']);
|
return response()->json(['status' => false, 'message' => 'Process fail']);
|
||||||
|
|
@ -123,7 +127,7 @@ class UserController extends Controller
|
||||||
if ($user) {
|
if ($user) {
|
||||||
if (!$user->qrcode) {
|
if (!$user->qrcode) {
|
||||||
// Generate the QR code and save it to storage
|
// Generate the QR code and save it to storage
|
||||||
QrCode::size(500)->margin(2)->generate($qrCodeContent, Storage::path('public/'.$filePath));
|
QrCode::size(500)->margin(2)->generate($qrCodeContent, Storage::path('public/' . $filePath));
|
||||||
// Update the user's record with the QR code file path
|
// Update the user's record with the QR code file path
|
||||||
$user->qrcode = $filePath;
|
$user->qrcode = $filePath;
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace App\Traits;
|
||||||
|
|
||||||
use App\Helper\Cache\CurrentMonthTimekeeping;
|
use App\Helper\Cache\CurrentMonthTimekeeping;
|
||||||
use App\Models\Notes;
|
use App\Models\Notes;
|
||||||
|
use App\Models\User;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
@ -100,7 +101,7 @@ trait AnalyzeData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result[] = ['user' => $admin, 'history' => $user_data];
|
$result[] = ['user' => $admin->id, 'history' => $user_data];
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
@ -119,4 +120,19 @@ trait AnalyzeData
|
||||||
CurrentMonthTimekeeping::cleanCacheCurrentMonthTimekeeping();
|
CurrentMonthTimekeeping::cleanCacheCurrentMonthTimekeeping();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function appendUsersInformation($results)
|
||||||
|
{
|
||||||
|
$users = User::all();
|
||||||
|
$data = [];
|
||||||
|
foreach($users as $user){
|
||||||
|
foreach($results as $result){
|
||||||
|
$result = (array)$result;
|
||||||
|
if($result['user'] === $user->id){
|
||||||
|
$data[] = ['user'=> $user, 'history' => $result['history']];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,7 @@ const data = [
|
||||||
label: 'Organization Settings',
|
label: 'Organization Settings',
|
||||||
icon: IconSettings,
|
icon: IconSettings,
|
||||||
group: 'admin',
|
group: 'admin',
|
||||||
|
permissions: 'admin',
|
||||||
},
|
},
|
||||||
// { link: '/jira', label: 'Jira', icon: IconSubtask },
|
// { link: '/jira', label: 'Jira', icon: IconSubtask },
|
||||||
// { link: '/custom-theme', label: 'Custom Theme', icon: IconBrush },
|
// { link: '/custom-theme', label: 'Custom Theme', icon: IconBrush },
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { getLeaveManagement, updateNoteLeave } from '@/api/Admin'
|
||||||
import { update } from '@/rtk/helpers/CRUD'
|
import { update } from '@/rtk/helpers/CRUD'
|
||||||
import { get } from '@/rtk/helpers/apiService'
|
import { get } from '@/rtk/helpers/apiService'
|
||||||
import {
|
import {
|
||||||
|
Avatar,
|
||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
Drawer,
|
Drawer,
|
||||||
|
|
@ -30,6 +31,7 @@ interface User {
|
||||||
email_verified_at: string | null
|
email_verified_at: string | null
|
||||||
permission: string
|
permission: string
|
||||||
remember_token: string | null
|
remember_token: string | null
|
||||||
|
avatar: string
|
||||||
created_at: string | null
|
created_at: string | null
|
||||||
updated_at: string | null
|
updated_at: string | null
|
||||||
}
|
}
|
||||||
|
|
@ -458,7 +460,13 @@ const LeaveManagement = () => {
|
||||||
<Table.Td ta={'center'}>{index + 1}</Table.Td>
|
<Table.Td ta={'center'}>{index + 1}</Table.Td>
|
||||||
<Table.Td>
|
<Table.Td>
|
||||||
<Tooltip multiline label={user.user.name}>
|
<Tooltip multiline label={user.user.name}>
|
||||||
<div>{user.user.name}</div>
|
<div style={{display:'flex', alignItems:'center'}}><Avatar size={'md'} mr={'md'} src={import.meta.env.VITE_BACKEND_URL.includes('local')
|
||||||
|
? import.meta.env.VITE_BACKEND_URL +
|
||||||
|
'storage/' +
|
||||||
|
user.user.avatar
|
||||||
|
: import.meta.env.VITE_BACKEND_URL +
|
||||||
|
'image/storage/' +
|
||||||
|
user.user.avatar}/>{user.user.name}</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</Table.Td>
|
</Table.Td>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import {
|
||||||
import { update, Xdelete } from '@/rtk/helpers/CRUD'
|
import { update, Xdelete } from '@/rtk/helpers/CRUD'
|
||||||
import { get } from '@/rtk/helpers/apiService'
|
import { get } from '@/rtk/helpers/apiService'
|
||||||
import {
|
import {
|
||||||
|
Avatar,
|
||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
Drawer,
|
Drawer,
|
||||||
|
|
@ -43,6 +44,7 @@ interface User {
|
||||||
email_verified_at: string | null
|
email_verified_at: string | null
|
||||||
permission: string
|
permission: string
|
||||||
remember_token: string | null
|
remember_token: string | null
|
||||||
|
avatar: string
|
||||||
created_at: string | null
|
created_at: string | null
|
||||||
updated_at: string | null
|
updated_at: string | null
|
||||||
}
|
}
|
||||||
|
|
@ -864,7 +866,13 @@ const Timekeeping = () => {
|
||||||
// offset={{ mainAxis: 5, crossAxis: 0 }}
|
// offset={{ mainAxis: 5, crossAxis: 0 }}
|
||||||
label={showTooltipAllNote(user)}
|
label={showTooltipAllNote(user)}
|
||||||
>
|
>
|
||||||
<div>{user.user.name}</div>
|
<div style={{display:'flex', alignItems:'center'}}><Avatar size={'md'} mr={'md'} src={import.meta.env.VITE_BACKEND_URL.includes('local')
|
||||||
|
? import.meta.env.VITE_BACKEND_URL +
|
||||||
|
'storage/' +
|
||||||
|
user.user.avatar
|
||||||
|
: import.meta.env.VITE_BACKEND_URL +
|
||||||
|
'image/storage/' +
|
||||||
|
user.user.avatar}/>{user.user.name}</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</Table.Td>
|
</Table.Td>
|
||||||
<Table.Td ta={'center'}>{totalDays}</Table.Td>
|
<Table.Td ta={'center'}>{totalDays}</Table.Td>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue