Changeset 4b7e2d3 for app


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
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • app/Exports/FilesExport.php

    rc6b84df r4b7e2d3  
    55use App\Models\File;
    66use App\Models\Folder;
    7 use App\Models\User;
    87use Maatwebsite\Excel\Concerns\FromCollection;
    98use Maatwebsite\Excel\Concerns\WithHeadings;
     
    2625            $row->location,
    2726            $row->getSize($row->location) . ' MB',
    28             $row->Folder::find($row->folder_id)->name . ' - ' . Folder::find($row->folder_id)->arch_id,
     27            $row->folder_id . ' - ' . Folder::find($row->folder_id)->name . ' - ' . Folder::find($row->folder_id)->arch_id,
    2928            $row->created_at,
    3029            $row->updated_at
     
    4039            'Location',
    4140            'Size',
    42             'Folder - Archive ID',
     41            'ID - Folder - Archive ID',
    4342            'Created at',
    4443            'Updated at'
  • app/Exports/FoldersExport.php

    rc6b84df r4b7e2d3  
    55use App\Models\Department;
    66use App\Models\Folder;
     7use App\Models\User;
    78use Maatwebsite\Excel\Concerns\FromCollection;
    89use Maatwebsite\Excel\Concerns\WithHeadings;
     
    2627            $row->note,
    2728            $row->location,
    28             $row->User::find($row->user_id)->username,
     29            $row->user_id . ' - ' . User::find($row->user_id)->username,
    2930            $row->Department::find($row->department_id)->name . ' - ' . Department::find($row->department_id)->code,
    3031            $row->is_important,
     
    4344            'Note',
    4445            'Location',
    45             'Created by',
     46            'Created by ID - Username',
    4647            'Department name - code',
    4748            'Is important',
  • app/Exports/UsersExport.php

    rc6b84df r4b7e2d3  
    2828            $row->phone_number,
    2929            $row->is_confirmed,
    30             $row->Role::find($row->role_id)->name,
     30            $row->role_id . ' - ' . Role::find($row->role_id)->name,
    3131            $row->where('id', $row->created_by)->pluck('username')->first(),
    3232            $row->created_at,
     
    4646            'Phone number',
    4747            'Is confirmed',
    48             'Role',
     48            'Role ID - Username',
    4949            'Created by',
    5050            'Created at',
  • 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    {
  • app/Models/Department.php

    rc6b84df r4b7e2d3  
    1414    protected $table = "departments";
    1515
    16     protected $fillable = ["name", "code", "location", "user_id"];
     16    protected $fillable = ["name", "code", "location", "user_id", "no_of_folders"];
    1717
    1818    protected $casts = [
  • app/Models/File.php

    rc6b84df r4b7e2d3  
    33namespace App\Models;
    44
     5use Illuminate\Database\Eloquent\Factories\HasFactory;
    56use Illuminate\Database\Eloquent\Model;
    67use Illuminate\Support\Facades\Storage;
     
    89class File extends Model
    910{
     11    use HasFactory;
     12
    1013    protected $table = "files";
    1114    protected $fillable = ["name", "location", "document_id"];
Note: See TracChangeset for help on using the changeset viewer.