gruppen löschen
This commit is contained in:
parent
5b1a91d847
commit
cf6b70b167
|
|
@ -6,9 +6,11 @@ return [
|
|||
'routes' => [
|
||||
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
|
||||
# AGENCY
|
||||
//['name' => 'agency#show', 'url' => '/getagencydata', 'verb' => 'GET'],
|
||||
['name' => 'agency#show', 'url' => '/getagencydata', 'verb' => 'GET'],
|
||||
['name' => 'agency#updateagencydata', 'url' => '/updateagencydata', 'verb' => 'PUT'],
|
||||
# GROUPS
|
||||
['name' => 'group#getagencygroups', 'url' => '/getagencygroups', 'verb' => 'GET'],
|
||||
['name' => 'group#addagencygroup', 'url' => '/addagencygroup', 'verb' => 'PUT'],
|
||||
# DEVELOPMENT
|
||||
['name' => 'test#filetest', 'url' => '/filetest', 'verb' => 'GET'],
|
||||
]
|
||||
|
|
|
|||
|
|
@ -13,11 +13,13 @@ class AgencyManager {
|
|||
|
||||
protected $agencyMapper;
|
||||
protected $groupManager;
|
||||
protected $userSession;
|
||||
protected $db;
|
||||
|
||||
public function __construct($AppName, IDBConnection $db, IRequest $request, AgencyMapper $agencyMapper, IGroupManager $groupManager) {
|
||||
public function __construct($AppName, IDBConnection $db, IRequest $request, AgencyMapper $agencyMapper, IGroupManager $groupManager, IUserSession $userSession) {
|
||||
$this->agencyMapper = $agencyMapper;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->userSession = $userSession;
|
||||
}
|
||||
/**
|
||||
* Creates a new Agency and save it to the database.
|
||||
|
|
@ -35,15 +37,11 @@ class AgencyManager {
|
|||
/**
|
||||
* getAgencyByUser
|
||||
*
|
||||
* @param:
|
||||
* - $request
|
||||
* - $userSession
|
||||
*
|
||||
* Return the Agency-ID by filtering the id from default agency-group, ex: agency_1 -> 1 (int)
|
||||
*
|
||||
*/
|
||||
public function getAgencyByUser(IUserSession $userSession){
|
||||
$groups = $this->groupManager->getUserGroups($userSession->getUser());
|
||||
public function getAgencyByUser(){
|
||||
$groups = $this->groupManager->getUserGroups($this->userSession->getUser());
|
||||
$agency_group_id = "";
|
||||
foreach($groups as $group){
|
||||
if(str_contains($group->getGId(), 'agencymaingroupid_')){
|
||||
|
|
@ -54,4 +52,15 @@ class AgencyManager {
|
|||
return $this->agencyMapper->getAgencyByGId($agency_group_id);
|
||||
#return $agency_group_id;
|
||||
}
|
||||
|
||||
// Return an random Id-Ele for generating single IDs
|
||||
public function generateRandomId($length = 6) {
|
||||
$characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
return $randomString;
|
||||
}
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ class AgencyController extends Controller {
|
|||
*
|
||||
*/
|
||||
public function show() {
|
||||
return $this->agencyManager->getAgencyByUser($this->userSession);
|
||||
return $this->agencyManager->getAgencyByUser();
|
||||
#return $this->handleNotFound(function () use ($id) {
|
||||
# return $this->service->find($id);
|
||||
#});
|
||||
|
|
@ -75,7 +75,7 @@ class AgencyController extends Controller {
|
|||
*/
|
||||
public function updateagencydata(string $name = null, string $inhaber = null, string $street = null, string $plz = null, string $city = null, string $agencymail = null, string $phone = null) {
|
||||
|
||||
$id = $this->agencyManager->getAgencyByUser($this->userSession)->getId();
|
||||
$id = $this->agencyManager->getAgencyByUser()->getId();
|
||||
|
||||
return $this->handleNotFound(function () use ($id, $name, $inhaber, $street, $plz, $city, $agencymail, $phone) {
|
||||
return $this->service->update($id, $name, $inhaber, $street, $plz, $city, $agencymail, $phone);
|
||||
|
|
|
|||
|
|
@ -4,54 +4,85 @@ declare(strict_types=1);
|
|||
namespace OCA\Agency\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Controller;
|
||||
|
||||
use OCA\Agency\Service\GroupService;
|
||||
use OCA\Agency\Agency\AgencyManager;
|
||||
|
||||
class GroupControllerController extends Controller {
|
||||
|
||||
class GroupController extends Controller {
|
||||
|
||||
private $service;
|
||||
private $Id;
|
||||
|
||||
protected $agencymanager;
|
||||
protected $userSession;
|
||||
protected $groupManager;
|
||||
use Errors;
|
||||
|
||||
public function __construct(string $AppName, IRequest $request,
|
||||
GroupService $service){
|
||||
GroupService $service, AgencyManager $agencymanager, IGroupManager $groupManager){
|
||||
parent::__construct($AppName, $request);
|
||||
$this->service = $service;
|
||||
$this->agencymanager = $agencymanager;
|
||||
$this->groupManager = $groupManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function index() {
|
||||
return new DataResponse($this->service->findAll($this->Id));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function show(int $id) {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->find($id);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $id
|
||||
* Returns all Groups of an Agency, incl. all Data (DisplayName, GId)
|
||||
*
|
||||
* TODO: Checken, ob der aktuelle Nutzer das auch darf!
|
||||
* TODO: Hier auch die Permissions später laden, damit das nicht nochmal requested werden muss.
|
||||
*
|
||||
*/
|
||||
public function destroy(int $id) {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->delete($id);
|
||||
});
|
||||
public function getagencygroups(){
|
||||
$searchGroupId = $this->agencymanager->getAgencyByUser()->getAgencygid();
|
||||
$groups = $this->groupManager->search($searchGroupId);
|
||||
$response_groups = array();
|
||||
foreach ($groups as $group) {
|
||||
// Checking, if group is default or not. Default Groups cant delete and cant rename by logged user!
|
||||
$isDefault = true;
|
||||
if(str_contains($group->getGId(), 'subgroup')){
|
||||
$isDefault = false;
|
||||
}
|
||||
array_push($response_groups, array('name' => $group->getDisplayName(), 'gid' => $group->getGid(), 'isDefault' => $isDefault));
|
||||
}
|
||||
//Sorting the Array A-Z by GroupDisplayName
|
||||
$keys = array_column($response_groups, 'name');
|
||||
array_multisort($keys, SORT_ASC, $response_groups);
|
||||
return $response_groups;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Creates a new Group by GroupName
|
||||
*
|
||||
* Not possible are groupnames which are used to seperate the agencys
|
||||
*
|
||||
* TODO: Check, if logged user has rights to do that!
|
||||
*
|
||||
* @NoAdminRequired
|
||||
*
|
||||
*/
|
||||
public function addagencygroup(string $groupname){
|
||||
if($groupname == "agencymaingroupid" or preg_match('~[0-9]{6}+~', $groupname) == 1){
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
$searchGroupId = $this->agencymanager->getAgencyByUser()->getAgencygid();
|
||||
$newGroupId = $searchGroupId.'_subgroup_'.$this->agencymanager->generateRandomId();
|
||||
while($this->groupManager->groupExists($newGroupId) == true){
|
||||
$newGroupId = $searchGroupId.'_subgroup_'.$this->agencymanager->generateRandomId();
|
||||
}
|
||||
|
||||
$newGroup = $this->groupManager->createGroup($newGroupId);
|
||||
$newGroup->setDisplayName($groupname);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -50,7 +50,10 @@ class TestController extends Controller {
|
|||
*/
|
||||
|
||||
//return $agency_group_id;
|
||||
return array("id" => 1, "name" => "DIETA");
|
||||
//if($groupname == "agencymaingroupid" || preg_match('/[0-9]^.{6}$')){
|
||||
// return false;
|
||||
//}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -10217,6 +10217,11 @@
|
|||
"tinycolor2": "1.4.2"
|
||||
}
|
||||
},
|
||||
"vue-confirm-dialog": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/vue-confirm-dialog/-/vue-confirm-dialog-1.0.2.tgz",
|
||||
"integrity": "sha512-gTo1bMDWOLd/6ihmWv8VlPxhc9QaKoE5YqlsKydUOfrrQ3Q3taljF6yI+1TMtAtJLrvZ8DYrePhgBhY1VCJzbQ=="
|
||||
},
|
||||
"vue-eslint-parser": {
|
||||
"version": "7.6.0",
|
||||
"resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-7.6.0.tgz",
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
"bootstrap-vue": "^2.21.2",
|
||||
"sass": "^1.34.1",
|
||||
"vue": "^2.6.12",
|
||||
"vue-confirm-dialog": "^1.0.2",
|
||||
"vue-router": "^3.5.1",
|
||||
"vuex": "^3.6.2"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2,28 +2,47 @@
|
|||
<b-card no-body>
|
||||
<b-card-header header-tag="header"
|
||||
role="tab">
|
||||
<b-button block @click="accordionToggle(index)" variant="secondary">{{ ele }}</b-button>
|
||||
<b-button block
|
||||
variant="secondary"
|
||||
@click="accordionToggle(index)">
|
||||
{{ group.name }}
|
||||
</b-button>
|
||||
<span v-if="group.isDefault"><small>Standardgruppe</small></span>
|
||||
<b-button v-if="!group.isDefault"
|
||||
style="float: right; "
|
||||
size="sm"
|
||||
variant=""
|
||||
@click="delGroup(group.gid)">
|
||||
<b-icon icon="trash-fill" aria-hidden="true" />
|
||||
</b-button>
|
||||
</b-card-header>
|
||||
<b-collapse :id="groupDefId + index "
|
||||
accordion="groupaccordion"
|
||||
role="tabpanel">
|
||||
<b-card-body>
|
||||
<b-card-text>I start opened because <code>visible</code> is <code>true</code></b-card-text>
|
||||
<b-card-text>Mein Text!</b-card-text>
|
||||
The GroupId is {{ group.gid }} <br>
|
||||
<span v-if="group.isDefault">Ist default</span>
|
||||
<span v-else>Nicht default</span>
|
||||
</b-card-body>
|
||||
</b-collapse>
|
||||
</b-card>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// import Content from '@nextcloud/vue/dist/Components/Content'
|
||||
|
||||
export default {
|
||||
name: 'Group',
|
||||
components: {
|
||||
},
|
||||
// Properties of Group-Elements
|
||||
props: ['index', 'ele'],
|
||||
props: {
|
||||
index: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
group: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// Main Group-ID for all Accordions
|
||||
|
|
@ -35,6 +54,21 @@ export default {
|
|||
accordionToggle(ele) {
|
||||
this.$root.$emit('bv::toggle::collapse', this.groupDefId + ele)
|
||||
},
|
||||
delGroup(id) {
|
||||
console.log(id)
|
||||
this.$confirm({
|
||||
message: 'Möchten Sie die Gruppe ' + this.group.name + ' löschen?',
|
||||
button: {
|
||||
no: 'Nein',
|
||||
yes: 'Ja',
|
||||
},
|
||||
callback: confirm => {
|
||||
if (confirm) {
|
||||
console.log('DO IT!')
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { BootstrapVue, BootstrapVueIcons } from 'bootstrap-vue'
|
|||
import 'bootstrap/dist/css/bootstrap.css'
|
||||
import 'bootstrap-vue/dist/bootstrap-vue.css'
|
||||
import 'bootstrap-vue/dist/bootstrap-vue-icons.min.css'
|
||||
import VueConfirmDialog from 'vue-confirm-dialog'
|
||||
// import store from './store'
|
||||
|
||||
Vue.use(VueRouter)
|
||||
|
|
@ -15,6 +16,7 @@ Vue.use(VueFormulate, {
|
|||
plugins: [de],
|
||||
locale: 'de',
|
||||
})
|
||||
Vue.use(VueConfirmDialog)
|
||||
Vue.use(BootstrapVue)
|
||||
Vue.use(BootstrapVueIcons)
|
||||
Vue.prototype.$hostname = 'http://localhost:8080'
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<Content app-name="AgencyData">
|
||||
<b-container fluid
|
||||
v-if="isLoading">
|
||||
<b-container v-if="isLoading"
|
||||
fluid>
|
||||
<h3>Agenturdaten</h3>
|
||||
<FormulateForm
|
||||
v-model="agency"
|
||||
|
|
|
|||
|
|
@ -1,24 +1,50 @@
|
|||
<template>
|
||||
<Content app-name="GroupManagement">
|
||||
<b-container fluid>
|
||||
<vue-confirm-dialog />
|
||||
<b-container
|
||||
v-if="isLoading"
|
||||
fluid>
|
||||
<h3>Gruppenverwaltung</h3>
|
||||
<div class="accordion" role="tablist">
|
||||
<Group no-body
|
||||
fluid
|
||||
v-for="(group, index) in groups"
|
||||
:key="group"
|
||||
<Group v-for="(group, index) in groups"
|
||||
:key="index"
|
||||
no-body
|
||||
:index="index"
|
||||
:ele="group" />
|
||||
:group="group" />
|
||||
</div>
|
||||
<hr>
|
||||
<FormulateForm
|
||||
name="groupform"
|
||||
@submit="submitHandler">
|
||||
<b-row>
|
||||
<b-col>
|
||||
<FormulateInput name="groupname"
|
||||
placeholder="Gruppenname"
|
||||
type="text"
|
||||
validation="required|max:30" />
|
||||
</b-col>
|
||||
</b-row>
|
||||
<b-row>
|
||||
<b-col>
|
||||
<b-button
|
||||
variant="secondary"
|
||||
type="submit">
|
||||
Neue Gruppe anlegen
|
||||
</b-button>
|
||||
</b-col>
|
||||
</b-row>
|
||||
</FormulateForm>
|
||||
</b-container>
|
||||
<b-container v-if="!isLoading" class="d-flex justify-content-center">
|
||||
<b-spinner type="grow" />
|
||||
</b-container>
|
||||
</Content>
|
||||
</template>
|
||||
<script>
|
||||
import Content from '@nextcloud/vue/dist/Components/Content'
|
||||
import Group from '../components/Group.vue'
|
||||
// import '@braid/vue-formulate/themes/snow/snow.scss'
|
||||
// import { generateUrl } from '@nextcloud/router'
|
||||
// const axios = require('axios').default
|
||||
import { generateUrl } from '@nextcloud/router'
|
||||
import axios from '@nextcloud/axios'
|
||||
|
||||
export default ({
|
||||
name: 'GroupManagement',
|
||||
|
|
@ -28,12 +54,26 @@ export default ({
|
|||
},
|
||||
data() {
|
||||
return {
|
||||
groups: ['Gruppe 1', 'Gruppe 2', 'Gruppe 3'],
|
||||
groups: [],
|
||||
isLoading: false,
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.loadingGroupData()
|
||||
},
|
||||
methods: {
|
||||
async loadingGroupData() {
|
||||
const groupResponse = await axios.get(generateUrl('/apps/agency/getagencygroups'))
|
||||
this.groups = groupResponse.data
|
||||
this.isLoading = true
|
||||
},
|
||||
async submitHandler(data) {
|
||||
const response = await axios.put(generateUrl('/apps/agency/addagencygroup'), data)
|
||||
if (response.data) {
|
||||
this.$formulate.reset('groupform')
|
||||
this.loadingGroupData()
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue