From 546f193561c253af1538333059cd1aa759cb99ca Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 6 Jul 2023 17:58:49 +0200 Subject: [PATCH] group admin area, new states --- src/client/app/js/app/core/Dict.js | 6 ++- src/client/app/js/app/gui/ActionButton.js | 40 +++++++++------- .../app/state/GroupMemberManagementMember.js | 40 ++++++++++++---- src/client/app/tmpl/group-detail.html | 15 ++++++ .../group-member-management-member-body.html | 5 +- src/client/app/tmpl/gui-actionbutton.html | 2 +- .../server/control/TB_Server_Control_Team.php | 48 +++++++++++++++++++ .../core/TB_Server_Core_Notification.php | 32 +++++++++++++ .../TB_Shared_Ent_TeamData_Appointment.php | 6 +++ .../TB_Shared_Ent_TeamData_Profile.php | 39 +++++++++++++++ 10 files changed, 203 insertions(+), 30 deletions(-) diff --git a/src/client/app/js/app/core/Dict.js b/src/client/app/js/app/core/Dict.js index 25d8c93..894bc29 100644 --- a/src/client/app/js/app/core/Dict.js +++ b/src/client/app/js/app/core/Dict.js @@ -547,7 +547,11 @@ app.core.Dict = { "GROUP_MANAGEMENT_MEMBERS_ACTIVE" : "Aktiv", "GROUP_MANAGEMENT_MEMBERS_INACTIVE" : "Inaktiv", "GROUP_MANAGEMENT_MEMBERS_NOT_APPROVED" : "Unbestätigt", - "GROUP_MANAGEMENT_MEMBERS_CHANGE_STATUS" : "Gruppenstatus ändern" + "GROUP_MANAGEMENT_MEMBERS_CHANGE_STATUS" : "Gruppenstatus ändern", + "BTN_GROUP_MANAGEMENT_MEMBERS_SAVE_STATUS" : "Status speichern", + "MEMBER_STATUS_CHANGED" : "Status erfolgreich geändert.", + "GROUP_DETAIL_NOTE_INACTIVE_OR_NOT_APPROVED" : "Du bist bereits Mitglied dieser Gruppe, deine volle Mitgliedschaft muss von einem Admin aktiviert werden. Aktuell kannst du noch keine Gruppentermine sehen oder an ihnen teilnehmen.", + "GROUP_DETAIL_STATUS" : "Dein Gruppenstatus", }, "en" : { } diff --git a/src/client/app/js/app/gui/ActionButton.js b/src/client/app/js/app/gui/ActionButton.js index 20b88af..3f8af79 100644 --- a/src/client/app/js/app/gui/ActionButton.js +++ b/src/client/app/js/app/gui/ActionButton.js @@ -148,23 +148,29 @@ app.gui.ActionButton = (function() return; } - switch ( stateId ) - { - case 'appointment-create': - case 'appointment-edit': - case 'appointment-edit-attendee': - case 'configuration-profile-edit': - case 'group-detail-edit': - case 'group-members-edit': - case 'group-member-management': - $actionButton.hide(); - break; - - default: - $actionButton.css( 'right', '20px' ); - $actionButton.css( 'marginRight', 0); - $actionButton.show(); - } + // switch ( stateId ) + // { + // case 'appointment-create': + // case 'appointment-edit': + // case 'appointment-edit-attendee': + // case 'configuration-profile-edit': + // case 'group-detail-edit': + // case 'group-members-edit': + // case 'group-member-management': + // $actionButton.hide(); + // break; + // + // default: + // $actionButton.css( 'right', '20px' ); + // $actionButton.css( 'marginRight', 0); + // $actionButton.show(); + // } + + // NOTE: Show by default - maybe there are some states when to hide action button later + $actionButton.css( 'right', '20px' ); + $actionButton.css( 'marginRight', 0); + $actionButton.show(); + }.bind( this )); } , diff --git a/src/client/app/js/app/state/GroupMemberManagementMember.js b/src/client/app/js/app/state/GroupMemberManagementMember.js index 5cc2ddf..e78521e 100644 --- a/src/client/app/js/app/state/GroupMemberManagementMember.js +++ b/src/client/app/js/app/state/GroupMemberManagementMember.js @@ -26,10 +26,6 @@ app.state.GroupMemberManagementMember = function() fnRenderMemberForm = function( profile ) { - console.log(profile); - //console.log(profile.getGroupData(groupId)); - // console.log(group); - //console.log(profile.getGroupData(groupId).status); $memberContainer = $content.find( '[data-id="member-container"]' ).first(); $memberContainer.html( app.core.View.getTemplate( @@ -198,10 +194,10 @@ app.state.GroupMemberManagementMember = function() $content.on( 'click', '[data-id="btn-update-role"]', function() { var newRole = $content.find( '[data-id="select-member-role"]' ).first().val(); - if ( memberToEdit.getRoleInGroup( group.getId() ) === newRole ) - { - return; - } + // if ( memberToEdit.getRoleInGroup( group.getId() ) === newRole ) + // { + // return; + // } app.gui.PageLoader.show(); app.core.Rpc.call( 'Team', @@ -223,6 +219,34 @@ app.state.GroupMemberManagementMember = function() ); }); + $content.on( 'click', '[data-id="btn-update-status"]', function() + { + var newStatus = $content.find( '[data-id="select-member-status"]' ).first().val(); + // if ( memberToEdit.getGroupData( group.getId() ).status === newStatus ) + // { + // return; + // } + app.gui.PageLoader.show(); + app.core.Rpc.call( + 'Team', + 'changeMemberStatus', + { + groupId : group.getId(), + memberId : memberToEdit.getId(), + newStatus : newStatus + }, + function( res ) + { + app.core.View.toastSuccess( _lc( 'MEMBER_STATUS_CHANGED' ) ); + if ( app.model.SessionUser.isOwnProfile( memberToEdit ) ) + { + app.core.Controller.redirect( '#/group/' + group.getId() ); + } + app.gui.PageLoader.hide(); + } + ); + }); + $content.on( 'click', '[data-id="btn-update-contract"]', function() { var contractUnix = null; diff --git a/src/client/app/tmpl/group-detail.html b/src/client/app/tmpl/group-detail.html index 2816963..b5de451 100644 --- a/src/client/app/tmpl/group-detail.html +++ b/src/client/app/tmpl/group-detail.html @@ -77,6 +77,21 @@ <% } %> +
+ <% var status = currentProfile.getGroupData( group.getId() ).status %> + <%= _lc( 'GROUP_DETAIL_STATUS' ) %>: + <% if ( status === 'active' ) { %> + <%= _lc( 'GROUP_MANAGEMENT_MEMBERS_ACTIVE' ) %> + <% } else if ( status === 'inactive' ) { %> + <%= _lc( 'GROUP_MANAGEMENT_MEMBERS_INACTIVE' ) %> + <% } else if ( status === 'not_approved' ) { %> + <%= _lc( 'GROUP_MANAGEMENT_MEMBERS_NOT_APPROVED' ) %> + <% } %> +
+ <% if ( status === 'inactive' || status === 'not_approved' ) { %> + <%= _lc( 'GROUP_DETAIL_NOTE_INACTIVE_OR_NOT_APPROVED' ) %> + <% } %> +
diff --git a/src/client/app/tmpl/group-member-management-member-body.html b/src/client/app/tmpl/group-member-management-member-body.html index 522d042..725777f 100644 --- a/src/client/app/tmpl/group-member-management-member-body.html +++ b/src/client/app/tmpl/group-member-management-member-body.html @@ -132,9 +132,8 @@
-
<% if ( 'trainer' === p.getRoleInGroup( g.getId() ) ) { %> diff --git a/src/client/app/tmpl/gui-actionbutton.html b/src/client/app/tmpl/gui-actionbutton.html index ee723f2..d01a55a 100644 --- a/src/client/app/tmpl/gui-actionbutton.html +++ b/src/client/app/tmpl/gui-actionbutton.html @@ -34,7 +34,7 @@
  • - +   <%= _lc( 'GROUP_EDIT_MEMBERS' ) %>
  • diff --git a/src/server/server/control/TB_Server_Control_Team.php b/src/server/server/control/TB_Server_Control_Team.php index be2a0aa..9ab45d2 100644 --- a/src/server/server/control/TB_Server_Control_Team.php +++ b/src/server/server/control/TB_Server_Control_Team.php @@ -237,6 +237,54 @@ class TB_Server_Control_Team { return $resp; } + public static function changeMemberStatus( TB_Server_Core_RequestData $params ) + { + $resp = new TB_Server_Core_Response(); + + $teamId = $params->get( 'groupId' ); + $team = TB_Shared_Ent_TeamData_Team::get( $teamId ); + $newStatus = $params->get( 'newStatus' ); + + if (!in_array($newStatus, TB_Shared_Ent_TeamData_Profile::getValidStates())) { + throw new \Exception( 'Invalid new status: ' . $newStatus ); + } + + if ( is_null( $team ) ) + { + throw new \Exception( 'Invalid group id for update member.' ); + } + + $sessionProfile = TB_Server_Core_Session::get()->getProfile(); + if ( false === $sessionProfile->isAdminOfTeam( $teamId ) ) + { + throw new \Exception( 'Not allowed to update member' ); + } + + $memberId = $params->get( 'memberId' ); + $memberToUpdate = TB_Shared_Ent_TeamData_Profile::get( $params->get( 'memberId' ) ); + if ( is_null( $memberToUpdate ) ) + { + throw new \Exception( 'cannot find member to update with id', $memberId ); + } + + if ( false === $memberToUpdate->isInTeam( $teamId ) ) + { + throw new \Exception( 'profile to update is not a member of current team.' ); + } + + if ( $memberToUpdate->isOwnerOfTeam( $teamId ) ) + { + throw new \Exception( 'Trainer cannot be updated within this function' ); + } + + $memberToUpdate->setStatusInTeam( $teamId, $newStatus ); + $memberToUpdate->save(); + + TB_Server_Core_Notification::notifyNewStatus( $memberToUpdate, $team, $newStatus ); + + return $resp; + } + public static function changeMemberContract( TB_Server_Core_RequestData $params ) { $resp = new TB_Server_Core_Response(); diff --git a/src/server/server/core/TB_Server_Core_Notification.php b/src/server/server/core/TB_Server_Core_Notification.php index a44589b..09ed2ce 100644 --- a/src/server/server/core/TB_Server_Core_Notification.php +++ b/src/server/server/core/TB_Server_Core_Notification.php @@ -262,6 +262,38 @@ class TB_Server_Core_Notification ); } + /** + * @param TB_Shared_Ent_TeamData_Profile $profile + * @param TB_Shared_Ent_TeamData_Team $group + * @param $newStatus + * @throws Exception + */ + public static function notifyNewStatus(TB_Shared_Ent_TeamData_Profile $profile, TB_Shared_Ent_TeamData_Team $group, $newStatus ) + { + $profileIds = array( $profile->id ); + + $statusText = ""; + switch ($newStatus) { + case TB_Shared_Ent_TeamData_Profile::STATUS_ACTIVE: + $statusText = 'Aktiv'; + break; + case TB_Shared_Ent_TeamData_Profile::STATUS_INACTIVE: + $statusText = 'Inaktiv'; + break; + case TB_Shared_Ent_TeamData_Profile::STATUS_NOT_APPROVED: + $statusText = 'Unbestätigt'; + break; + } + + $msg = 'Deine Status im Team ' . $group->display_name . ' wurde auf ' . $statusText. ' gesetzt.'; + TB_Server_Core_Notification::sendToProfiles( + 'Neuer Status', + $msg, + $profileIds, + TB_Server_Core_Notification::createAdditionalData( '#/group/members' . $group->id, true ) + ); + } + /** * @param TB_Shared_Ent_TeamData_Profile $profile * @param TB_Shared_Ent_TeamData_Team $group diff --git a/src/server/shared/ent/teamdata/TB_Shared_Ent_TeamData_Appointment.php b/src/server/shared/ent/teamdata/TB_Shared_Ent_TeamData_Appointment.php index 372ae0e..61caff2 100644 --- a/src/server/shared/ent/teamdata/TB_Shared_Ent_TeamData_Appointment.php +++ b/src/server/shared/ent/teamdata/TB_Shared_Ent_TeamData_Appointment.php @@ -381,6 +381,12 @@ class TB_Shared_Ent_TeamData_Appointment extends Francis_Db_Row } } + // Check if user is not approved in group yet + $profileTeamData = $profile->getTeamsData($this->team_id); + if ($profileTeamData['status'] === TB_Shared_Ent_TeamData_Profile::STATUS_NOT_APPROVED) { + $isVisible = false; + } + return $isVisible; } diff --git a/src/server/shared/ent/teamdata/TB_Shared_Ent_TeamData_Profile.php b/src/server/shared/ent/teamdata/TB_Shared_Ent_TeamData_Profile.php index 3936bc0..4185d6a 100644 --- a/src/server/shared/ent/teamdata/TB_Shared_Ent_TeamData_Profile.php +++ b/src/server/shared/ent/teamdata/TB_Shared_Ent_TeamData_Profile.php @@ -69,6 +69,15 @@ class TB_Shared_Ent_TeamData_Profile extends Francis_Db_Row { ); } + public static function getValidStates() + { + return array( + self::STATUS_ACTIVE, + self::STATUS_INACTIVE, + self::STATUS_NOT_APPROVED + ); + } + /** * Get first profile by account id * @param $accountId @@ -395,6 +404,36 @@ class TB_Shared_Ent_TeamData_Profile extends Francis_Db_Row { $this->teams_js = $profileTeamData; } + /** + * @param $teamId + * @param $status + */ + public function setStatusInTeam($teamId, $status ) + { + if ( !in_array( $status, self::getValidStates() ) ) + { + throw new \Exception( "Invalid status to set: " . $status ); + } + + $profileTeamData = array(); + if ( is_array( $this->teams_js ) ) + { + // Make a copy + $profileTeamData = unserialize( serialize( $this->teams_js ) ); + } + + + foreach( $profileTeamData as &$teamData ) + { + if ( $teamId === $teamData[ 'team_id' ] ) + { + $teamData[ 'status' ] = $status; + } + } + + $this->teams_js = $profileTeamData; + } + /** * @param $teamId * @param $contract