diff --git a/appinfo/routes.php b/appinfo/routes.php
index 7f9c32b..14bb5b9 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -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'],
]
diff --git a/lib/Agency/AgencyManager.php b/lib/Agency/AgencyManager.php
index b3feb0d..03951b7 100644
--- a/lib/Agency/AgencyManager.php
+++ b/lib/Agency/AgencyManager.php
@@ -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.
@@ -34,16 +36,12 @@ 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;
+ }
}
\ No newline at end of file
diff --git a/lib/Controller/AgencyController.php b/lib/Controller/AgencyController.php
index 8b5a995..15751f3 100644
--- a/lib/Controller/AgencyController.php
+++ b/lib/Controller/AgencyController.php
@@ -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);
diff --git a/lib/Controller/GroupController.php b/lib/Controller/GroupController.php
index 001359d..7fe4c31 100644
--- a/lib/Controller/GroupController.php
+++ b/lib/Controller/GroupController.php
@@ -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;
+ }
}
}
\ No newline at end of file
diff --git a/lib/Controller/TestController.php b/lib/Controller/TestController.php
index bce936c..407ba85 100644
--- a/lib/Controller/TestController.php
+++ b/lib/Controller/TestController.php
@@ -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;
}
}
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index f62c709..67fcb26 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -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",
diff --git a/package.json b/package.json
index 540d829..70b8c86 100644
--- a/package.json
+++ b/package.json
@@ -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"
},
diff --git a/src/components/Group.vue b/src/components/Group.vue
index abee947..c1a0c89 100644
--- a/src/components/Group.vue
+++ b/src/components/Group.vue
@@ -2,28 +2,47 @@
- {{ ele }}
+
+ {{ group.name }}
+
+ Standardgruppe
+
+
+
- I start opened because visible is true
- Mein Text!
+ The GroupId is {{ group.gid }}
+ Ist default
+ Nicht default
-
diff --git a/src/main.js b/src/main.js
index a90e0f4..7e7b466 100644
--- a/src/main.js
+++ b/src/main.js
@@ -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'
diff --git a/src/views/AgencyData.vue b/src/views/AgencyData.vue
index 12fee5c..8e1c4fc 100644
--- a/src/views/AgencyData.vue
+++ b/src/views/AgencyData.vue
@@ -1,7 +1,7 @@
-
+
Agenturdaten
-
+
+
Gruppenverwaltung
-
+ :group="group" />
+
+
+
+
+
+
+
+
+
+
+ Neue Gruppe anlegen
+
+
+
+
+
+
+