99 prioritize
1010 v-slot =" { text, action }"
1111 >
12+ <Button
13+ v-if =" !isSuper"
14+ :icon =" areAllCheckedInAllGroups() ? 'checkbox-uncheck' : 'checkbox'"
15+ @click =" toggleAllInAllGroups()"
16+ :text =" areAllCheckedInAllGroups() ? __('Uncheck All') : __('Check All')"
17+ />
1218 <Button type =" submit" variant =" primary" @click =" action" :text =" text" />
1319 </CommandPaletteItem >
1420 </Header >
4955 </Panel >
5056
5157 <div v-if =" !isSuper" class =" space-y-6 mt-6" >
52- <CardPanel v-for =" group in permissions" :key =" group.handle" :heading =" group.label" >
53- <PermissionTree :depth =" 1" :initial-permissions =" group.permissions" />
54- </CardPanel >
58+ <Panel :heading =" group.label" v-for =" group in permissions" :key =" group.handle" >
59+ <template #header-actions >
60+ <Button
61+ size =" sm"
62+ variant =" subtle"
63+ :icon =" areAllChecked(group) ? 'checkbox-uncheck' : 'checkbox'"
64+ @click =" toggleAllInGroup(group)"
65+ >
66+ {{ areAllChecked(group) ? __('Uncheck All') : __('Check All') }}
67+ </Button >
68+ </template >
69+ <Card >
70+ <PermissionTree :depth =" 1" :initial-permissions =" group.permissions" />
71+ </Card >
72+ </Panel >
5573 </div >
5674 </div >
5775</template >
5876
5977<script >
60- import { Header , Button , CardPanel , Panel , PanelHeader , Heading , Card , Switch , Field , Input , CommandPaletteItem } from ' @/components/ui' ;
78+ import { Header , Button , Panel , PanelHeader , Heading , Card , Switch , Field , Input , CommandPaletteItem } from ' @/components/ui' ;
6179import { requireElevatedSession } from ' @/components/elevated-sessions' ;
6280import PermissionTree from ' @/components/roles/PermissionTree.vue' ;
6381import { router } from ' @inertiajs/vue3' ;
@@ -74,7 +92,6 @@ export default {
7492 PermissionTree,
7593 Header,
7694 Button,
77- CardPanel,
7895 Panel,
7996 PanelHeader,
8097 Heading,
@@ -141,6 +158,50 @@ export default {
141158 },
142159
143160 methods: {
161+ areAllChecked (group ) {
162+ const checkAll = (permissions ) => {
163+ return permissions .every (permission => {
164+ const childrenChecked = permission .children && permission .children .length
165+ ? checkAll (permission .children )
166+ : true ;
167+ return permission .checked && childrenChecked;
168+ });
169+ };
170+ return checkAll (group .permissions );
171+ },
172+
173+ areAllCheckedInAllGroups () {
174+ return this .permissions .every (group => this .areAllChecked (group));
175+ },
176+
177+ toggleAllInGroup (group ) {
178+ const allChecked = this .areAllChecked (group);
179+ const toggle = (permissions , checked ) => {
180+ permissions .forEach (permission => {
181+ permission .checked = checked;
182+ if (permission .children && permission .children .length ) {
183+ toggle (permission .children , checked);
184+ }
185+ });
186+ };
187+ toggle (group .permissions , ! allChecked);
188+ },
189+
190+ toggleAllInAllGroups () {
191+ const allChecked = this .areAllCheckedInAllGroups ();
192+ this .permissions .forEach (group => {
193+ const toggle = (permissions , checked ) => {
194+ permissions .forEach (permission => {
195+ permission .checked = checked;
196+ if (permission .children && permission .children .length ) {
197+ toggle (permission .children , checked);
198+ }
199+ });
200+ };
201+ toggle (group .permissions , ! allChecked);
202+ });
203+ },
204+
144205 clearErrors () {
145206 this .error = null ;
146207 this .errors = {};
0 commit comments