From 6baa7d04c73a41c9e6f8a047e0ca2b0994fc3f35 Mon Sep 17 00:00:00 2001 From: katmastt Date: Mon, 9 Oct 2023 13:30:37 +0000 Subject: [PATCH] fixed notification widget and notification history errors --- components/NotificationWidget.php | 9 ++--- controllers/SiteController.php | 18 ++++++---- controllers/TicketAdminController.php | 15 ++++++-- controllers/TicketUserController.php | 4 +-- models/JupyterRequestNew.php | 8 ++--- models/MachineComputeRequest.php | 6 ++++ models/OndemandRequest.php | 7 ++-- views/project/new_jupyter_request.php | 2 +- views/project/new_machine_compute_request.php | 2 +- views/project/new_service_request.php | 2 +- views/site/notification_history.php | 34 ++++++++++++++----- 11 files changed, 73 insertions(+), 34 deletions(-) diff --git a/components/NotificationWidget.php b/components/NotificationWidget.php index 50bbd05..77b96a3 100644 --- a/components/NotificationWidget.php +++ b/components/NotificationWidget.php @@ -73,6 +73,11 @@ public static function createMenuItem() $items[]=['label'=>'View notification history', 'url'=>['site/notification-history'],'options'=>['class'=>'notification-history']]; + if ($notifCount!=0) + { + $items[]=['label'=>'Mark all as seen','options'=>['id'=>'mark_all_seen']]; + } + foreach ($notifications as $notification) { $type=$typeClass[$notification->type]; @@ -80,10 +85,6 @@ public static function createMenuItem() 'options'=>['class'=>"notification $type"]]; } // $items[]=['label'=>'View notification history', 'url'=>['site/notification-history'],'options'=>['class'=>'notification-history']]; - if ($notifCount!=0) - { - $items[]=['label'=>'Mark all as seen','options'=>['id'=>'mark_all_seen']]; - } return [$label,$items]; diff --git a/controllers/SiteController.php b/controllers/SiteController.php index 78e2666..9327e3c 100644 --- a/controllers/SiteController.php +++ b/controllers/SiteController.php @@ -260,18 +260,22 @@ public function actionNotificationRedirect($id) { return $this->redirect(['project/index']); } - // if ($notification->type == 0 && Userw::hasRole('Admin', $superadminAllowed=true)){ + if ($notification->type == 0 && Userw::hasRole('Admin', $superadminAllowed=true)){ // $url=$notification->url.'&mode=0'; - // return $this->redirect($url); - // } else { - // $ticket_id = substr($notification->url, -2); - // $url = 'index.php?r=ticket-user%2Fview&id='.$ticket_id; + return $this->redirect($notification->url); + } elseif ($notification->type == 0) { + $url_split = explode('=', $notification->url); + $ticket_id = $url_split[2]; + $url = 'index.php?r=ticket-user%2Fview&id='.$ticket_id; // // $url=$notification->url.'&mode=0'; // Yii::$app->session->setFlash('success', "HEY"); // return $this->redirect($url); // } // Yii::$app->session->setFlash('success', "HEY 2"); - return $this->redirect($notification->url); + return $this->redirect($url); + } else{ + return $this->redirect($notification->url); + } } @@ -290,7 +294,7 @@ public function actionNotificationHistory() $notifications=$results[1]; - return $this->render('notification_history',['notifications'=>$notifications,'pages'=>$pages,'typeClass'=>$typeClass,]); + return $this->render('notification_history',['notifications'=>$notifications,'pages'=>$pages,'typeClass'=>$typeClass]); } public function actionSshTutorial() diff --git a/controllers/TicketAdminController.php b/controllers/TicketAdminController.php index 61b80ef..ae115d7 100755 --- a/controllers/TicketAdminController.php +++ b/controllers/TicketAdminController.php @@ -103,7 +103,7 @@ public function actionAnswer($id, $mode, $url1=1) $username=explode('@',$newTicket->name_user)[0]; $message="Administrator $username posted an answer for ticket $ticketHead->topic."; - $url=Url::to(['/ticket-admin/view','id'=>$id]); + $url=Url::to(['/ticket-admin/view','id'=>$id, 'mode'=>$mode]); $currentUser=Yii::$app->user->identity->id; /* @@ -117,9 +117,20 @@ public function actionAnswer($id, $mode, $url1=1) ->andWhere(['<>','u.id',$currentUser]) ->all(); + //but send only one notification to each user, despite of how many times he answered to the ticket + $id_already_sent = array(); foreach ($ids as $id) { - Notification::notify($id['id'], $message, Notification::NORMAL ,$url); + $found=0; + foreach ($id_already_sent as $id_already){ + if ($id_already==$id['id']){ + $found=1; + } + } + if ($found==0){ + array_push($id_already_sent, $id['id']); + Notification::notify($id['id'], $message, Notification::NORMAL ,$url); + } } return $this->redirect(Url::to(['/ticket-admin/index'])); diff --git a/controllers/TicketUserController.php b/controllers/TicketUserController.php index c5cb2c5..e63b2e9 100755 --- a/controllers/TicketUserController.php +++ b/controllers/TicketUserController.php @@ -112,7 +112,7 @@ public function actionView($id) $username=explode('@',$newTicket->name_user)[0]; $message="User $username posted an answer for ticket $ticket->topic."; - $url=Url::to(['/ticket-user/view','id'=>$id]); + $url=Url::to(['/ticket-admin/answer','id'=>$id, 'mode'=>0]); //added to fix the following error foreach (User::getAdminIds() as $admin) @@ -193,7 +193,7 @@ public function actionOpen($link='', $upgrade=0) $username=explode('@',$ticketBody->name_user)[0]; $message="User $username created a new $ticketHead->department ticket with the following topic:
$ticketHead->topic."; - $url=Url::to(['/ticket-admin/answer','id'=>$ticketHead->id]); + $url=Url::to(['/ticket-admin/answer','id'=>$ticketHead->id, 'mode'=>0]); foreach (User::getAdminIds() as $admin) { Notification::notify($admin, $message, '0' ,$url); diff --git a/models/JupyterRequestNew.php b/models/JupyterRequestNew.php index b91ebc8..01f6a10 100644 --- a/models/JupyterRequestNew.php +++ b/models/JupyterRequestNew.php @@ -200,8 +200,8 @@ public function uploadNew($requestId) foreach ($request->user_list as $user) { - //need to create a new type of notifications - Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved'])); + Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'auto-approved'])); + // Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved'])); } $project->latest_project_request_id=$request->id; @@ -297,8 +297,8 @@ public function uploadNewEdit($requestId,$uchanged) foreach ($request->user_list as $user) { - - Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved'])); + Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'auto-approved'])); + // Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved'])); } diff --git a/models/MachineComputeRequest.php b/models/MachineComputeRequest.php index a31edf9..f21f45a 100644 --- a/models/MachineComputeRequest.php +++ b/models/MachineComputeRequest.php @@ -89,6 +89,8 @@ public function init() $flavors=$response->data['flavors']; // print_r($flavors); // exit(0); + usort($flavors, "self::cmp"); + foreach ($flavors as $flavor) { $name=$flavor['name']; @@ -389,4 +391,8 @@ public function getDiff($other) { return $diff; } + + public function cmp($a, $b){ + return strcmp($a['vcpus'], $b['vcpus']); + } } diff --git a/models/OndemandRequest.php b/models/OndemandRequest.php index cf9b3c6..2a0bacd 100644 --- a/models/OndemandRequest.php +++ b/models/OndemandRequest.php @@ -198,7 +198,8 @@ public function uploadNew($requestId) { - Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved'])); + // Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved'])); + Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'auto-approved'])); } $project->latest_project_request_id=$request->id; @@ -279,8 +280,8 @@ public function uploadNewEdit($requestId,$uchanged) foreach ($request->user_list as $user) { - - Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved'])); + Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'auto-approved'])); + // Notification::notify($user,$message,2,Url::to(['project/user-request-list','filter'=>'approved'])); } diff --git a/views/project/new_jupyter_request.php b/views/project/new_jupyter_request.php index 3df8bc3..2a25b89 100644 --- a/views/project/new_jupyter_request.php +++ b/views/project/new_jupyter_request.php @@ -60,7 +60,7 @@ 'Request a new books project', +['title'=>'Request a new on-demand notebooks project', ]) ?> diff --git a/views/project/new_machine_compute_request.php b/views/project/new_machine_compute_request.php index 7c0e090..e6f850b 100644 --- a/views/project/new_machine_compute_request.php +++ b/views/project/new_machine_compute_request.php @@ -99,7 +99,7 @@
 
- field($service,'flavour')->dropDownList($service->flavours)->label($flavour_label)?> + field($service,'flavour')->dropDownList(array_reverse($service->flavours))->label($flavour_label)?> field($service,'num_of_vms')->dropDownList($num_vms_dropdown)?>
diff --git a/views/project/new_service_request.php b/views/project/new_service_request.php index e9667fc..10793d1 100644 --- a/views/project/new_service_request.php +++ b/views/project/new_service_request.php @@ -126,7 +126,7 @@
 
- field($service,'flavour')->dropDownList($service->flavours)->label($flavour_label)?> + field($service,'flavour')->dropDownList(array_reverse($service->flavours))->label($flavour_label)?>
diff --git a/views/site/notification_history.php b/views/site/notification_history.php index 42fdfd3..573da1a 100644 --- a/views/site/notification_history.php +++ b/views/site/notification_history.php @@ -10,6 +10,7 @@ use yii\helpers\Html; use yii\widgets\LinkPager; +use webvimark\modules\UserManagement\models\User as Userw; $this->title="Notification History"; @@ -38,9 +39,10 @@ if (!empty($notifications)) { +//table-striped didn't show the correct color for every second same type notification ?> - +
@@ -56,15 +58,29 @@ ?> - - + + + + +
Notification message
- - - + + + +