Changeset e6c1f87 for app/Http


Ignore:
Timestamp:
10/18/21 19:54:18 (3 years ago)
Author:
beratkjufliju <kufliju@…>
Branches:
develop, master
Children:
b9c4a92
Parents:
bd9e8e3
Message:

added pagination, is_important

Location:
app/Http
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • app/Http/Controllers/Dashboard/DepartmentsController.php

    rbd9e8e3 re6c1f87  
    3636        $department->code = $request->code;
    3737
     38        $len = Storage::disk('local')->path('');
     39
    3840        if(!Storage::disk('local')->has('Departments/' . $request->code)){
    3941            Storage::disk('local')->makeDirectory('Departments/' . $request->code);
     
    4143
    4244        $department->user_id = auth()->id();
    43         $department->location = '/Departments/' . $request->code;
     45        $department->location =  Storage::disk('local')->path('') . 'Departments/' . $request->code;
    4446
    4547        $department->save();
     
    6567        $department->name = $request->name;
    6668        $department->code = $request->code;
    67         $department->updated_at = Carbon::now();;
    6869
    69         $path = '/Departments/' . $request->code;
    70         $department->location = $path;
     70        $department->location =  Storage::disk('local')->path('') . 'Departments/' . $request->code;
    7171
    7272        $files = Storage::allFiles($oldDepartmentCode);
  • app/Http/Controllers/Dashboard/DocumentsController.php

    rbd9e8e3 re6c1f87  
    1717    public function index(Request $request)
    1818    {
     19        $queries = explode(" ", $request->search);
     20        $result = collect();
     21
     22        foreach ($queries as $query) {
     23            $result->push(Document::where("arch_id", "like", "%{$query}%")->orWhere("name", "like", "%{$query}%")->get());
     24        }
     25
     26        $result = $result->flatten();
     27
     28
    1929        if ($request->query('id')) {
    20             $documents = Document::where('department_id', $request->query('id'))->get();
    21         } else {
    22             $documents = Document::all();
     30
     31            $documentsInDeptSort = Document::with('department')->when($request->has('id'), function($query) use ($request) {
     32                $query->where('department_id', $request->query('id'));
     33            });
     34
     35            if($request->query('sort') == 'newest') {
     36                $documents = $documentsInDeptSort->orderBy('created_at', 'desc')->paginate(20);
     37            }
     38            else if($request->query('sort') == 'name') {
     39                $documents = $documentsInDeptSort->orderBy('name', 'asc')->paginate(20);
     40            }
     41            else{
     42                $documents = Document::where('department_id', $request->query('id'))->paginate(20);
     43            }
     44        }
     45        else {
     46            if($request->query('sort') == 'newest') {
     47                $documents = Document::orderBy('created_at', 'desc')->paginate(20);
     48            }
     49            else if($request->query('sort') == 'name') {
     50                $documents = Document::orderBy('name', 'asc')->paginate(20);
     51            }
     52            else if($request->query('sort') == 'important'){
     53                $documents = Document::where('is_important', true)->paginate(20);
     54            }
     55            else if($request->query('sort') == 'recent') {
     56               $documents = Document::orderBy('created_at', 'desc')->paginate(20);
     57            }
     58            else if($request->query('search')){
     59                $result = collect();
     60
     61                foreach ($queries as $query) {
     62                    $result->push(Document::where("arch_id", "like", "%{$query}%")->orWhere("name", "like", "%{$query}%")->get());
     63                }
     64                $result = $result->flatten();
     65                $documents = $result;
     66            }
     67            else
     68            {
     69                $documents = Document::paginate(20);
     70            }
    2371        }
    2472
    2573        $departments = Department::all();
     74
     75        $diskTotal = disk_total_space('/');
     76        $diskTotalSize = $diskTotal / 1073741824;
     77
     78        $diskFree  = disk_free_space('/');
     79        $used = $diskTotal - $diskFree;
     80
     81        $diskUsedSize = $used / 1073741824;
     82        $diskUse1 = round(100 - (($diskUsedSize / $diskTotalSize) * 100));
     83        $diskUse = round(100 - ($diskUse1)) . '%';
    2684
    2785        return view("dashboard.documents.index")->with([
     
    3088            "departments" => $departments,
    3189            "docsCount" => Department::withCount('document')->get(),
    32             'totalDocs' => Document::all()->count()
     90            "totalDocs" => Document::all()->count(),
     91            "countImportant" => Document::where('is_important', true)->get()->count(),
     92            "diskTotal" => $diskTotal,
     93            "diskTotalSize" => $diskTotalSize,
     94            "diskUse" => $diskUse,
     95            "diskUsedSize" => $diskUsedSize
     96
    3397        ]);
    3498
     
    40104            "departments" => Department::all()
    41105        ]);
     106    }
     107
     108    public function store(DocumentRequest $request, UploadService $uploadService)
     109    {
     110        $document = new Document();
     111        $user = auth()->user();
     112        $department = Department::find($request->department);
     113
     114        $document->user()->associate($user);
     115        $document->department()->associate($department);
     116
     117        $document->arch_id = $request->arch_id;
     118        $document->name = $request->name;
     119        $document->description = $request->description;
     120
     121        if (!Storage::disk('local')->has($document->department()->pluck('location')->join("") . '/' . $request->arch_id)) {
     122            Storage::disk('local')->makeDirectory($document->department()->pluck('location')->join("") . '/' . $request->arch_id);
     123        }
     124
     125        $documentFile = $uploadService->upload(File::class, [
     126            "file_item" => $request->file_item,
     127        ], "link", true);
     128
     129        $document->save();
     130
     131        foreach ($documentFile as $df) {
     132            $file = File::find($df);
     133            $file->document()->associate($document);
     134            $file->save();
     135        }
     136
     137        Alert::flash("New document created successfully");
     138
     139        return redirect()->route("dashboard.documents.index");
    42140    }
    43141
     
    73171    }
    74172
    75     public function store(DocumentRequest $request, UploadService $uploadService)
    76     {
    77         $document = new Document();
    78         $user = auth()->user();
    79         $department = Department::find($request->department);
    80 
    81         $document->user()->associate($user);
    82         $document->department()->associate($department);
    83 
    84         $document->arch_id = $request->arch_id;
    85         $document->name = $request->name;
    86         $document->description = $request->description;
    87 
    88         if (!Storage::disk('local')->has($document->department()->pluck('location')->join("") . '/' . $request->arch_id)) {
    89             Storage::disk('local')->makeDirectory($document->department()->pluck('location')->join("") . '/' . $request->arch_id);
    90         }
    91 
    92         $documentFile = $uploadService->upload(File::class, [
    93             "file_item" => $request->file_item,
    94         ], "link", true);
    95 
     173    public function toggleImportant($id)
     174    {
     175        $document = Document::find($id);
     176        $document->is_important = !$document->is_important;
    96177        $document->save();
    97178
    98         foreach ($documentFile as $df) {
    99             $file = File::find($df);
    100             $file->document()->associate($document);
    101             $file->save();
    102         }
    103 
    104         Alert::flash("New document created successfully");
    105 
     179        if($document->is_important==true)
     180        Alert::flash("Document marked as important successfully");
     181        else
     182            Alert::flash("Document marked as not important successfully");
     183
     184        return redirect()->back();
     185    }
     186
     187    public function search(Request $request)
     188    {
     189        $queries = explode(" ", $request->q);
     190        $result = collect();
     191
     192        foreach ($queries as $query) {
     193            $result->push(Document::where("arch_id", "like", "%{$query}%")->orWhere("name", "like", "%{$query}%")->get());
     194        }
     195
     196        $result = $result->flatten();
     197
     198        $departments = Department::all();
     199
     200        return view("dashboard.documents.search")
     201            ->with("searchQuery", $request->q)
     202            ->with("results", $result)
     203            ->with("departments", $departments)
     204            ->with("countImportant", Document::where('is_important', true)->get()->count());
     205    }
     206
     207    public function destroy($id)
     208    {
     209        $document = Document::find($id);
     210        if (auth()->user()->hasPermission("delete_all_posts")) {
     211            $document->delete();
     212            Alert::flash($document->name . " deleted successfully");
     213        }
    106214        return redirect()->route("dashboard.documents.index");
    107215    }
    108 
    109216}
  • app/Http/Controllers/Dashboard/SettingsController.php

    rbd9e8e3 re6c1f87  
    33namespace App\Http\Controllers\Dashboard;
    44
     5use App\Helpers\Alert;
    56use App\Http\Requests\Dashboard\EmailSettingsRequest;
    67use App\Http\Requests\Dashboard\PasswordSettingsRequest;
     
    1011use App\Notifications\VerifyNewEmail;
    1112use Carbon\Carbon;
     13use Illuminate\Contracts\Validation\Validator;
     14use Illuminate\Http\Request;
     15use Illuminate\Validation\ValidationException;
    1216
    1317class SettingsController extends Controller
     
    1721        return view("dashboard.settings.index")->with([
    1822            "user" => auth()->user(),
    19             "adminAndEditors" => User::where("role_id", 1)->orWhere("role_id", 2)->get(),
     23            "adminAndReferents" => User::where("role_id", 1)->orWhere("role_id", 2)->get(),
    2024            "active_tab" => "account"
    2125        ]);
     
    2428    public function updateUsername(UsernameSettingsRequest $request)
    2529    {
    26         if ($request->validated()) {
    2730            $user = auth()->user();
    2831            $user->username = $request->username;
     
    3336
    3437            return redirect()->route("auth.loginShow");
    35         } else {
    36             return back()->with(['active_tab' => 'security']);
    37         }
    38 
    39         dd('no');
    4038    }
    4139
    42     public function updatePassword(PasswordSettingsRequest $request)
     40    public function updatePassword(UsernameSettingsRequest $request)
    4341    {
    44         $user = auth()->user();
    45         $user->password = bcrypt($request->password);
    46         $user->save();
     42            $user = auth()->user();
     43            $user->password = bcrypt($request->password);
     44            $user->save();
    4745
    48         auth()->logout();
    49         session()->flush();
     46            auth()->logout();
     47            session()->flush();
    5048
    51         return redirect()->route("auth.loginShow");
     49            return redirect()->route("auth.loginShow");
    5250    }
    5351
  • app/Http/Requests/Dashboard/DocumentRequest.php

    rbd9e8e3 re6c1f87  
    33namespace App\Http\Requests\Dashboard;
    44
     5use App\Models\Department;
    56use App\Models\Document;
    67use App\Models\FileType;
     
    3839                    $arch_id = $this->request->get('arch_id');
    3940                    $deptId = explode('/', $arch_id)[0];
    40                     if ($deptId !== $this->request->get('department')) {
    41                         $fail("Dept id error");
     41                    if ($deptId !== Department::find($this->request->get('department'))->code) {
     42                        $fail("Document Archive ID field format is invalid");
    4243                    }
    4344                }
  • app/Http/Requests/Dashboard/UsernameSettingsRequest.php

    rbd9e8e3 re6c1f87  
    3535        $response = redirect()
    3636            ->route('dashboard.settings.index')
    37             ->with(['active_tab' => 'security'])
     37            ->withInput(['active_tab' => 'security'])
    3838            ->withErrors($validator);
    3939
    40         throw (new ValidationException($validator, $response))
     40        throw (new ValidationException($validator))
    4141            ->errorBag($this->errorBag)
    4242            ->redirectTo($this->getRedirectUrl());
Note: See TracChangeset for help on using the changeset viewer.