Changeset 4b7e2d3 for app/Http


Ignore:
Timestamp:
10/23/21 04:03:46 (3 years ago)
Author:
beratkjufliju <kufliju@…>
Branches:
develop, master
Children:
b39afb5
Parents:
c6b84df
Message:

bug fixes, edited export, added fileSeeder for DB testing

Location:
app/Http/Controllers/Dashboard
Files:
6 edited

Legend:

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

    rc6b84df r4b7e2d3  
    147147        if(!$flag) {
    148148            $zip->close();
    149             $headers = array('Content-Type' => 'application/octet-stream',);
     149            $headers = array('Content-Type' => 'application/octet-stream');
    150150            $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . '- Departments.zip';
    151151            return response()->download($zip_file, $zip_new_name, $headers);
     
    153153        else {
    154154            Alert::flash("All departments are empty", "warning");
    155             return redirect()->route("dashboard.departments.index");
     155            return redirect()->back();
    156156        }
    157157    }
     
    186186        else{
    187187            Alert::flash("This department has no files", "warning");
    188             return redirect()->route("dashboard.departments.index");
     188            return redirect()->back();
    189189        }
    190190
  • app/Http/Controllers/Dashboard/ExportExcelController.php

    rc6b84df r4b7e2d3  
    33namespace App\Http\Controllers\Dashboard;
    44
     5use App\Exports\DepartmentsExport;
    56use App\Exports\FilesExport;
    67use App\Exports\FoldersExport;
     
    3233
    3334    }
     35
     36    public function ExportDepartments()
     37    {
     38        return Excel::download(new DepartmentsExport(), Carbon::now()->format('d.m.Y - H:i') . ' - departments.xlsx');
     39
     40    }
     41
    3442}
  • app/Http/Controllers/Dashboard/FilesController.php

    rc6b84df r4b7e2d3  
    2626            "textExt" => array("txt", "doc", "docx"),
    2727            "imageExt" => array("png", "jpg", "jpeg"),
    28             "fileTypes" => '.' . implode(',.', explode(',', explode(':', FileType::find('1')->mimes)[1]))
     28            "fileTypes" => '.' . implode(',.', explode(',', FileType::find('1')->mimes))
    2929        ]);
    3030    }
     
    3535        $file->delete();
    3636        Storage::disk('uploads')->delete($file->location);
     37        $file->folder()->decrement('no_of_files');
    3738
    3839        Alert::flash($file->name . " deleted successfully");
     
    5960                $newFile->location = $location . DIRECTORY_SEPARATOR . $fileName;
    6061                $newFile->folder()->associate($folder);
     62                $newFile->folder()->increment('no_of_files');
    6163                $newFile->save();
    6264            }
     
    6567            Alert::flash("New files added successfully");
    6668
    67             return redirect()->route("dashboard.files.index");
     69            return redirect()->back();
    6870        }
    6971        else {
    7072            Alert::flash("No files were uploaded", "error");
    7173
    72             return redirect()->route("dashboard.files.index");
     74            return redirect()->back();
    7375        }
    7476    }
  • app/Http/Controllers/Dashboard/FoldersController.php

    rc6b84df r4b7e2d3  
    3939                $folders = $foldersInDeptSort->orderBy('name', 'asc')->paginate(12);
    4040            }
     41            else if ($request->query('sort') == 'no_of_files') {
     42                $folders = $foldersInDeptSort->orderBy('no_of_files', 'desc')->paginate(12);
     43            }
    4144            else if($request->query('sort') == 'count'){
    4245                $total = $foldersInDeptSort->folder->files->count();
     
    5255            else if ($request->query('sort') == 'name') {
    5356                $folders = Folder::orderBy('name', 'asc')->paginate(12);
     57            }
     58            else if ($request->query('sort') == 'no_of_files') {
     59                $folders = Folder::orderBy('no_of_files', 'desc')->paginate(12);
    5460            }
    5561            else if ($request->query('sort') == 'important') {
     
    97103            "deptName" => $deptName,
    98104            "deptCode" => $deptCode,
    99             "fileTypes" => '.' . implode(',.', explode(',', explode(':', FileType::find('1')->mimes)[1]))
     105            "fileTypes" => '.' . implode(',.', explode(',', FileType::find('1')->mimes))
    100106        ]);
    101107
     
    117123        $folder->user()->associate($user);
    118124        $folder->department()->associate($department);
     125        $folder->department()->increment('no_of_folders');
    119126
    120127        $folder->arch_id = $request->arch_id;
     
    149156                $newFile->location = $location . DIRECTORY_SEPARATOR . $fileName;
    150157                $newFile->folder()->associate($folder);
     158                $newFile->folder()->increment('no_of_files');
    151159                $newFile->save();
    152160            }
     
    155163        Alert::flash("New folder created successfully");
    156164
    157         return redirect()->route("dashboard.folders.index");
     165        return redirect()->back();
    158166    }
    159167
     
    177185        $department = Department::find($request->department);
    178186
    179         $folder->department()->associate($department);
    180 
    181         $oldLocation = $folder->department->location . DIRECTORY_SEPARATOR . $folder->name;
     187        $folder->department()->increment('no_of_folders');
     188
     189        $oldLocation = $folder->location;
    182190
    183191        $folder->name = $request->name;
     
    186194        $folder->updated_at = Carbon::now();
    187195
    188         $location = $folder->department->location . DIRECTORY_SEPARATOR . $request->name;
    189 
    190         if ($folder->isDirty('name')) {
    191             if (!Storage::disk('uploads')->has($location)) {
    192                 Storage::disk('uploads')->move($oldLocation, $location);
    193                 foreach($files as $file){
    194                     $file->location = $location . DIRECTORY_SEPARATOR . $file->name;
     196       $newLocation = Department::find($request->department)->location . DIRECTORY_SEPARATOR . $request->name;
     197
     198        if($folder->department_id != $request->department){
     199            $folder->department()->decrement('no_of_folders');
     200            if (!Storage::disk('uploads')->has($newLocation)) {
     201                Storage::disk('uploads')->move($oldLocation, $newLocation);
     202                foreach($files as $file) {
     203                    $file->location = $newLocation . DIRECTORY_SEPARATOR . $file->name;
    195204                    $file->save();
    196205                }
    197206            }
    198207        }
     208         if($folder->isDirty('name')) {
     209            if (!Storage::disk('uploads')->has($newLocation)) {
     210                Storage::disk('uploads')->move($oldLocation, $newLocation);
     211                foreach($files as $file) {
     212                    $file->location = $newLocation . DIRECTORY_SEPARATOR . $file->name;
     213                    $file->save();
     214                }
     215            }
     216        }
     217
     218        $folder->department()->associate($department);
     219
     220        $folder->location = $newLocation;
    199221
    200222        if ($request->has('file_item')) {
    201223            foreach ($request->file_item as $file) {
    202224                $fileName = $folder->name . '-' . uniqid() . '.' . $file->getClientOriginalExtension();
    203                     $file->storeAs($location . DIRECTORY_SEPARATOR, $fileName);
     225                    $file->storeAs($newLocation . DIRECTORY_SEPARATOR, $fileName);
    204226                    $newFile = new File();
    205227                    $newFile->name = $fileName;
    206                     $newFile->location = $location . DIRECTORY_SEPARATOR . $fileName;
     228                    $newFile->location = $newLocation . DIRECTORY_SEPARATOR . $fileName;
    207229                    $newFile->folder()->associate($folder);
     230                    $newFile->folder()->increment('no_of_files');
    208231                    $newFile->save();
    209232            }
    210233        }
    211234
    212         $folder->location = $location;
    213 
    214235        $folder->save();
    215 
    216236
    217237        Alert::flash("Folder edited successfully");
     
    246266            $location = $folder->department->location . DIRECTORY_SEPARATOR . $folder->name;
    247267            Storage::disk('uploads')->deleteDirectory($location);
     268            $folder->department()->decrement('no_of_folders');
    248269            Alert::flash($folder->name . " deleted successfully");
     270            return redirect()->back();
    249271        }
    250272        Alert::flash($folder->name . " is important", "error");
    251         return redirect()->route("dashboard.folders.index");
     273        return redirect()->back();
    252274    }
    253275
     
    306328        }
    307329        else {
    308             $files = File::where('folder_id', $id)->paginate(10);
     330            $files = File::where('folder_id', $id)->paginate(12);
    309331        }
    310332
     
    317339            "imageExt" => array("png", "jpg", "jpeg"),
    318340            "folders" => $folders,
    319             "fileTypes" => '.' . implode(',.', explode(',', explode(':', FileType::find('1')->mimes)[1]))
     341            "fileTypes" => '.' . implode(',.', explode(',', FileType::find('1')->mimes))
    320342        ]);
    321343    }
  • app/Http/Controllers/Dashboard/IndexController.php

    rc6b84df r4b7e2d3  
    99use App\Models\User;
    1010use App\Http\Controllers\Controller;
     11use Carbon\Carbon;
     12use Illuminate\Support\Facades\DB;
    1113
    1214class IndexController extends Controller
     
    1820        );
    1921
     22        $date = Carbon::today()->subDays(5);
     23        $recentFiles = File::where('created_at', '>=', $date)->get();
     24
     25        $year = ['2021','2022','2023','2024', '2025'];
     26
     27        $file = [];
     28        foreach ($year as $key => $value) {
     29            $file[] = File::where(DB::raw("DATE_FORMAT(created_at, '%Y')"),$value)->count();
     30        }
     31
    2032        return view("dashboard.index")->with([
    2133            "counters" => $counters,
     34            "largestDepartments" => Department::orderBy('no_of_folders', 'desc')->limit(10)->get(),
     35            "folders" => Folder::all(),
     36            "files" => File::all(),
     37            "recentFiles" => $recentFiles,
     38            "year" => json_encode($year,JSON_NUMERIC_CHECK),
     39            "file" => json_encode($file,JSON_NUMERIC_CHECK),
    2240            "departments" => Department::all(),
    23             "folders" => Folder::all(),
    24             "files" => File::all()
    25         ]);
     41            "excelExt" => array("xls", "xlsx", "xls", "csv"),
     42            "textExt" => array("txt", "doc", "docx"),
     43            "imageExt" => array("png", "jpg", "jpeg"),
     44
     45         ]);
    2646    }
    2747}
  • app/Http/Controllers/Dashboard/SettingsController.php

    rc6b84df r4b7e2d3  
    7777    }
    7878
    79 
    80 
    8179    public function fileTypes(FileTypeRequest $request)
    8280    {
Note: See TracChangeset for help on using the changeset viewer.