diff --git a/app/Console/Commands/MakeFile.php b/app/Console/Commands/MakeFile.php new file mode 100644 index 0000000..47e7a77 --- /dev/null +++ b/app/Console/Commands/MakeFile.php @@ -0,0 +1,67 @@ +faker = Factory::create(); + + parent::__construct(); + } + + /** + * Execute the console command. + * + * @return int + */ + public function handle() + { + $count = $this->argument('count'); + $this->info('Creating ' . $this->argument('count') . ' files!'); + + for ($max = 1; $max < $count; $max++) + { + Storage::disk('local')->put('factory_files/testfile_' . rand(0, 5000) . '.txt', $this->faker->paragraphs(40, true)); + + } + + $this->info('Finished creating files! They will be randomly picked by the factory.'); + return 0; + } +} diff --git a/app/Http/Controllers/TeamFileController.php b/app/Http/Controllers/TeamFileController.php new file mode 100644 index 0000000..b8a67e8 --- /dev/null +++ b/app/Http/Controllers/TeamFileController.php @@ -0,0 +1,111 @@ +currentTeam)) + { + $request->session()->flash('error', 'Please choose a team before viewing it\'s files.'); + return redirect()->to(route('teams.index')); + } + + return view('dashboard.teams.team-files') + ->with('files', TeamFile::with('team', 'uploader')->paginate(20)); + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + // + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(Request $request) + { + // + } + + + public function download(Request $request, TeamFile $teamFile) + { + try + { + return Storage::download('uploads/' . $teamFile->name); + } + catch (FileNotFoundException $ex) + { + $request->session()->flash('error', 'Sorry, but the requested file could not be found in storage. Sometimes, files may be physically deleted by admins, but not from the app\'s database.'); + return redirect()->back(); + + } + } + + /** + * Display the specified resource. + * + * @param \App\TeamFile $teamFile + * @return \Illuminate\Http\Response + */ + public function show(TeamFile $teamFile) + { + // + } + + /** + * Show the form for editing the specified resource. + * + * @param \App\TeamFile $teamFile + * @return \Illuminate\Http\Response + */ + public function edit(TeamFile $teamFile) + { + // + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param \App\TeamFile $teamFile + * @return \Illuminate\Http\Response + */ + public function update(Request $request, TeamFile $teamFile) + { + // + } + + /** + * Remove the specified resource from storage. + * + * @param \App\TeamFile $teamFile + * @return \Illuminate\Http\Response + */ + public function destroy(TeamFile $teamFile) + { + // + } +} diff --git a/app/Team.php b/app/Team.php index f7fe0fd..27fe33c 100644 --- a/app/Team.php +++ b/app/Team.php @@ -36,4 +36,10 @@ class Team extends TeamworkTeam { return $this->belongsToMany('App\Vacancy', 'team_has_vacancy'); } + + + public function files() + { + return $this->hasMany('App\TeamFile', 'team_id'); + } } diff --git a/app/TeamFile.php b/app/TeamFile.php new file mode 100644 index 0000000..8e54c14 --- /dev/null +++ b/app/TeamFile.php @@ -0,0 +1,31 @@ +belongsTo('App\User', 'uploaded_by', 'id'); + } + + public function team() + { + return $this->belongsTo('App\Team'); + } +} diff --git a/app/User.php b/app/User.php index b17aa9c..7ab469f 100644 --- a/app/User.php +++ b/app/User.php @@ -60,7 +60,8 @@ class User extends Authenticatable implements MustVerifyEmail 'email_verified_at' => 'datetime', ]; -// + // RELATIONSHIPS + public function applications() { return $this->hasMany('App\Application', 'applicantUserID', 'id'); @@ -86,6 +87,13 @@ class User extends Authenticatable implements MustVerifyEmail return $this->hasMany('App\Comment', 'authorID', 'id'); } + public function files() + { + return $this->hasMany('App\TeamFile', 'uploaded_by'); + } + + // UTILITY LOGIC + public function isBanned() { return ! $this->bans()->get()->isEmpty(); diff --git a/config/adminlte.php b/config/adminlte.php index 0d0e7de..197962b 100644 --- a/config/adminlte.php +++ b/config/adminlte.php @@ -607,22 +607,23 @@ return [ 'location' => 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/css/bootstrap-multiselect.css', ], ], - [ - 'name' => 'DropzoneJS', - 'active' => true, - 'files' => [ - [ - 'type' => 'js', - 'asset' => false, - 'location' => '/js/plugins/dropzone.min.js' - ], - [ - 'type' => 'css', - 'asset' => false, - 'location' => '/css/dropzone.min.css' - ] - ] - ] + ], + [ + 'name' => 'DropzoneJS', + 'active' => true, + 'files' => [ + [ + 'type' => 'js', + 'asset' => false, + 'location' => '/js/plugins/dropzone.min.js' + ], + [ + 'type' => 'css', + 'asset' => false, + 'location' => '/css/dropzone.min.css' + ] + ] + ] ], ]; diff --git a/database/factories/TeamFileFactory.php b/database/factories/TeamFileFactory.php new file mode 100644 index 0000000..7782137 --- /dev/null +++ b/database/factories/TeamFileFactory.php @@ -0,0 +1,38 @@ +getAdapter()->getPathPrefix(); + + return [ + 'uploaded_by' => rand(1, 10), // Also assuming that the user seeder has ran before + 'team_id' => rand(1, 3), // Assuming you create 3 teams beforehand + 'name' => $this->faker->file($prefix . 'factory_files', $prefix . 'uploads', false), + 'caption' => $this->faker->sentence(), + 'description' => $this->faker->paragraphs(3, true), + 'fs_location' => $this->faker->file($prefix . 'factory_files', $prefix . 'uploads'), + 'extension' => 'txt', + 'size' => rand(1, 1000) // random fake size between 0 bytes and 1 mb + ]; + } +} diff --git a/database/migrations/2020_10_10_185952_create_team_files_table.php b/database/migrations/2020_10_10_185952_create_team_files_table.php new file mode 100644 index 0000000..b1b0835 --- /dev/null +++ b/database/migrations/2020_10_10_185952_create_team_files_table.php @@ -0,0 +1,48 @@ +id(); + $table->bigInteger('uploaded_by')->unsigned()->index(); + $table->integer('team_id')->unsigned()->index(); + $table->string('name'); + $table->string('fs_location'); // filesystem location + $table->string('extension'); + $table->timestamps(); + + $table->foreign('uploaded_by') + ->references('id') + ->on('users') + ->cascadeOnDelete() + ->cascadeOnUpdate(); + + $table->foreign('team_id') + ->references('id') + ->on('teams') + ->cascadeOnDelete() + ->cascadeOnUpdate(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('team_files'); + } +} diff --git a/database/migrations/2020_10_10_235319_add_details_to_team_files.php b/database/migrations/2020_10_10_235319_add_details_to_team_files.php new file mode 100644 index 0000000..0ea7fd0 --- /dev/null +++ b/database/migrations/2020_10_10_235319_add_details_to_team_files.php @@ -0,0 +1,36 @@ +integer('size')->nullable()->after('extension'); + $table->string('caption')->nullable()->after('name'); + $table->mediumText('description')->nullable()->after('caption'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('team_files', function (Blueprint $table) { + $table->dropColumn('size'); + $table->dropColumn('caption'); + $table->dropColumn('description'); + }); + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index b267f30..51ae93b 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -35,5 +35,8 @@ class DatabaseSeeder extends Seeder $this->call(PermissionSeeder::class); $this->call(UserSeeder::class); $this->call(DefaultOptionsSeeder::class); + $this->call(NewPermissions::class); + $this->call(TeamSeeder::class); + $this->call(TeamFileSeeder::class); } } diff --git a/database/seeders/TeamFileSeeder.php b/database/seeders/TeamFileSeeder.php new file mode 100644 index 0000000..91f88c2 --- /dev/null +++ b/database/seeders/TeamFileSeeder.php @@ -0,0 +1,19 @@ +count(50)->create(); + } +} diff --git a/public/img/files.svg b/public/img/files.svg new file mode 100644 index 0000000..3900853 --- /dev/null +++ b/public/img/files.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/textfile.png b/public/img/textfile.png new file mode 100644 index 0000000..b0b5011 Binary files /dev/null and b/public/img/textfile.png differ diff --git a/resources/views/dashboard/teams/team-files.blade.php b/resources/views/dashboard/teams/team-files.blade.php new file mode 100644 index 0000000..d0b19da --- /dev/null +++ b/resources/views/dashboard/teams/team-files.blade.php @@ -0,0 +1,113 @@ +@extends('adminlte::page') + +@section('title', config('app.name') . ' | Team Files') + +@section('content_header') +
# | +File name | +Caption | +Size | +Last updated | +Actions | +
---|---|---|---|---|---|
{{$file->id}} | +{{ Str::of($file->name)->limit(10, '(..).' . $file->extension) }} | +{{ Str::of($file->caption)->limit(10) }} | +{{ $file->size }} bytes | +{{ $file->updated_at }} | ++ + + + | +