Verified Commit 855cb245 authored by Alex ORLUC's avatar Alex ORLUC

FEAT #11296 TIME 2 add autocomplete folders route

parent 17f22518
......@@ -86,6 +86,7 @@ $app->get('/autocomplete/users/visa', \SrcCore\controllers\AutoCompleteControlle
$app->get('/autocomplete/entities', \SrcCore\controllers\AutoCompleteController::class . ':getEntities');
$app->get('/autocomplete/statuses', \SrcCore\controllers\AutoCompleteController::class . ':getStatuses');
$app->get('/autocomplete/banAddresses', \SrcCore\controllers\AutoCompleteController::class . ':getBanAddresses');
$app->get('/autocomplete/folders', \SrcCore\controllers\AutoCompleteController::class . ':getFolders');
//Baskets
$app->get('/baskets', \Basket\controllers\BasketController::class . ':get');
......
......@@ -598,7 +598,7 @@ class FolderController
// login (string) : Login of user connected
// folderId (integer) : Check specific folder
// edition (boolean) : whether user can edit or not
private static function getScopeFolders(array $aArgs)
public static function getScopeFolders(array $aArgs)
{
$login = $aArgs['login'];
$userEntities = EntityModel::getWithUserEntities(['select' => ['entities.id'], 'where' => ['user_id = ?'], 'data' => [$login]]);
......
......@@ -16,6 +16,20 @@ use SrcCore\models\DatabaseModel;
class FolderModelAbstract
{
public static function get(array $aArgs)
{
$folders = DatabaseModel::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => ['folders'],
'where' => empty($aArgs['where']) ? [] : $aArgs['where'],
'data' => empty($aArgs['data']) ? [] : $aArgs['data'],
'order_by' => empty($aArgs['orderBy']) ? ['label'] : $aArgs['orderBy']
]);
return $folders;
}
public static function getById(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['id']);
......
......@@ -28,6 +28,8 @@ use SrcCore\models\TextFormatModel;
use SrcCore\models\ValidatorModel;
use Status\models\StatusModel;
use User\models\UserModel;
use Folder\models\FolderModel;
use Folder\controllers\FolderController;
class AutoCompleteController
{
......@@ -673,4 +675,37 @@ class AutoCompleteController
return ['contact' => $contact];
}
public static function getFolders(Request $request, Response $response)
{
$data = $request->getQueryParams();
$check = Validator::stringType()->notEmpty()->validate($data['search']);
if (!$check) {
return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
}
$scopedFolders = FolderController::getScopeFolders(['login' => $GLOBALS['userId']]);
$getScopedFoldersIds = function ($value) {
return $value['id'];
};
$arrScopedFoldersIds = array_map($getScopedFoldersIds, $scopedFolders);
$selectedFolders = FolderModel::get([
'where' => ['label ilike ? AND id IN(?)'],
'data' => [ '%'.$data['search'].'%', $arrScopedFoldersIds],
'orderBy' => ['label']
]);
$getFomatedFolders = function ($value) {
return $return = [
'id' => $value['id'],
'idToDisplay' => $value['label'],
'otherInfo' => ''
];
};
return $response->withJson(array_map($getFomatedFolders, $selectedFolders));
}
}
......@@ -4,6 +4,6 @@
<i class="fa fa-folder"></i>&nbsp;{{lang.folders}}
</mat-panel-title>
</mat-expansion-panel-header>
<plugin-autocomplete [size]="'small'" [labelPlaceholder]="lang.searchFolder" [labelList]="lang.searchFolder" [routeDatas]="['/rest/autocomplete/folders']" [targetSearchKey]="'idToDisplay'"></plugin-autocomplete>
<plugin-autocomplete [size]="'small'" [labelPlaceholder]="lang.searchFolder" [routeDatas]="['/rest/autocomplete/folders']" [targetSearchKey]="'idToDisplay'" (triggerEvent)="goTo($event)"></plugin-autocomplete>
<folder-tree #folderTree [selectedId]="id" (refreshDocList)="refreshDocList()"></folder-tree>
</mat-expansion-panel>
import { Component, OnInit, Input, ViewChild, Output, EventEmitter } from '@angular/core';
import { LANG } from '../../translate.component';
import { FolderTreeComponent } from '../folder-tree.component';
import { Router } from '@angular/router';
declare function $j(selector: any): any;
......@@ -18,7 +19,7 @@ export class PanelFolderComponent implements OnInit {
@Output('refreshEvent') refreshEvent = new EventEmitter<string>();
constructor() { }
constructor(private router: Router) { }
ngOnInit(): void { }
......@@ -41,4 +42,8 @@ export class PanelFolderComponent implements OnInit {
refreshFoldersTree() {
this.folderTree.getFolders();
}
goTo(folder: any) {
this.router.navigate(["/folders/" + folder.id]);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment