Merge pull request #503 from pixelfed/frontend-ui-refactor

Frontend ui refactor
This commit is contained in:
daniel 2018-10-16 15:40:36 -06:00 committed by GitHub
commit c8ff9194c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 378 additions and 49 deletions

View file

@ -21,6 +21,12 @@ class Follower extends Model
return $this->belongsTo(Profile::class, 'following_id', 'id'); return $this->belongsTo(Profile::class, 'following_id', 'id');
} }
public function permalink()
{
$path = $this->actor->permalink("/follow/{$this->id}");
return url($path);
}
public function toText() public function toText()
{ {
$actorName = $this->actor->username; $actorName = $this->actor->username;

View file

@ -64,12 +64,12 @@ class AccountController extends Controller
]); ]);
$profile = Auth::user()->profile; $profile = Auth::user()->profile;
$action = $request->input('a'); $action = $request->input('a');
$timeago = Carbon::now()->subMonths(1); $timeago = Carbon::now()->subMonths(3);
$following = $profile->following->pluck('id'); $following = $profile->following->pluck('id');
$notifications = Notification::whereIn('actor_id', $following) $notifications = Notification::whereIn('actor_id', $following)
->where('profile_id', '!=', $profile->id) ->where('profile_id', '!=', $profile->id)
->whereDate('created_at', '>', $timeago) ->whereDate('created_at', '>', $timeago)
->orderBy('notifications.id', 'desc') ->orderBy('notifications.created_at', 'desc')
->simplePaginate(30); ->simplePaginate(30);
return view('account.following', compact('profile', 'notifications')); return view('account.following', compact('profile', 'notifications'));

View file

@ -22,6 +22,7 @@ class StatusController extends Controller
$user = Profile::whereUsername($username)->firstOrFail(); $user = Profile::whereUsername($username)->firstOrFail();
$status = Status::whereProfileId($user->id) $status = Status::whereProfileId($user->id)
->where('visibility', '!=', 'draft')
->withCount(['likes', 'comments', 'media']) ->withCount(['likes', 'comments', 'media'])
->findOrFail($id); ->findOrFail($id);
@ -41,7 +42,7 @@ class StatusController extends Controller
$template = $this->detectTemplate($status); $template = $this->detectTemplate($status);
$replies = Status::whereInReplyToId($status->id)->simplePaginate(30); $replies = Status::whereInReplyToId($status->id)->orderBy('created_at', 'desc')->simplePaginate(30);
return view($template, compact('user', 'status', 'replies')); return view($template, compact('user', 'status', 'replies'));
} }
@ -59,6 +60,9 @@ class StatusController extends Controller
if ($status->viewType() == 'video') { if ($status->viewType() == 'video') {
$template = 'status.show.video'; $template = 'status.show.video';
} }
if ($status->viewType() == 'video-album') {
$template = 'status.show.video-album';
}
return $template; return $template;
}); });
@ -85,13 +89,7 @@ class StatusController extends Controller
} }
$this->validate($request, [ $this->validate($request, [
'photo.*' => function() { 'photo.*' => 'required|mimetypes:' . config('pixelfed.media_types').'|max:' . config('pixelfed.max_photo_size'),
return [
'required',
'mimes:' . config('pixelfed.media_types'),
'max:' . config('pixelfed.max_photo_size'),
];
},
'caption' => 'string|max:'.config('pixelfed.max_caption_length'), 'caption' => 'string|max:'.config('pixelfed.max_caption_length'),
'cw' => 'nullable|string', 'cw' => 'nullable|string',
'filter_class' => 'nullable|string', 'filter_class' => 'nullable|string',

View file

@ -29,6 +29,7 @@ class TimelineController extends Controller
->pluck('filterable_id'); ->pluck('filterable_id');
$timeline = Status::whereIn('profile_id', $following) $timeline = Status::whereIn('profile_id', $following)
->whereNotIn('profile_id', $filtered) ->whereNotIn('profile_id', $filtered)
->whereVisibility('public')
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->withCount(['comments', 'likes']) ->withCount(['comments', 'likes'])
->simplePaginate(20); ->simplePaginate(20);

View file

@ -32,4 +32,32 @@ class Media extends Model
return url($url); return url($url);
} }
public function mimeType()
{
return explode('/', $this->mime)[0];
}
public function activityVerb()
{
$verb = 'Image';
switch ($this->mimeType()) {
case 'image':
break;
case 'video':
$verb = 'Video';
break;
default:
$verb = 'Document';
break;
}
return $verb;
}
public function getMetadata()
{
return json_decode($this->metadata, true, 3);
}
} }

View file

@ -23,7 +23,7 @@ class Profile extends Model
'private_key', 'private_key',
]; ];
protected $visible = ['id', 'username', 'name']; protected $visible = ['username', 'name'];
public function user() public function user()
{ {
@ -51,6 +51,10 @@ class Profile extends Model
public function emailUrl() public function emailUrl()
{ {
if($this->domain) {
return $this->username;
}
$domain = parse_url(config('app.url'), PHP_URL_HOST); $domain = parse_url(config('app.url'), PHP_URL_HOST);
return $this->username.'@'.$domain; return $this->username.'@'.$domain;
@ -137,7 +141,7 @@ class Profile extends Model
{ {
$url = Cache::remember("avatar:{$this->id}", 1440, function () { $url = Cache::remember("avatar:{$this->id}", 1440, function () {
$path = optional($this->avatar)->media_path; $path = optional($this->avatar)->media_path;
$version = hash('sha1', $this->avatar->created_at); $version = hash('sha1', $this->avatar->updated_at);
$path = "{$path}?v={$version}"; $path = "{$path}?v={$version}";
return url(Storage::url($path)); return url(Storage::url($path));

View file

@ -18,6 +18,8 @@ class Status extends Model
*/ */
protected $dates = ['deleted_at']; protected $dates = ['deleted_at'];
protected $fillable = ['profile_id', 'visibility'];
public function profile() public function profile()
{ {
return $this->belongsTo(Profile::class); return $this->belongsTo(Profile::class);
@ -36,16 +38,21 @@ class Status extends Model
public function viewType() public function viewType()
{ {
$media = $this->firstMedia(); $media = $this->firstMedia();
$type = explode('/', $media->mime); $mime = explode('/', $media->mime)[0];
$count = $this->media()->count();
$type = ($mime == 'image') ? 'image' : 'video';
if($count > 1) {
$type = ($type == 'image') ? 'album' : 'video-album';
}
return $type[0]; return $type;
} }
public function thumb($showNsfw = false) public function thumb($showNsfw = false)
{ {
$type = $this->viewType(); $type = $this->viewType();
$is_nsfw = !$showNsfw ? $this->is_nsfw : false; $is_nsfw = !$showNsfw ? $this->is_nsfw : false;
if ($this->media->count() == 0 || $is_nsfw || $type != 'image') { if ($this->media->count() == 0 || $is_nsfw || !in_array($type,['image', 'album'])) {
return 'data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; return 'data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==';
} }

View file

@ -23,8 +23,8 @@ class AccountTransformer extends Fractal\TransformerAbstract
'url' => $profile->url(), 'url' => $profile->url(),
'avatar' => $profile->avatarUrl(), 'avatar' => $profile->avatarUrl(),
'avatar_static' => $profile->avatarUrl(), 'avatar_static' => $profile->avatarUrl(),
'header' => '', 'header' => null,
'header_static' => '', 'header_static' => null,
'moved' => null, 'moved' => null,
'fields' => null, 'fields' => null,
'bot' => null, 'bot' => null,

View file

@ -11,7 +11,7 @@ class MediaTransformer extends Fractal\TransformerAbstract
{ {
return [ return [
'id' => $media->id, 'id' => $media->id,
'type' => 'image', 'type' => $media->activityVerb(),
'url' => $media->url(), 'url' => $media->url(),
'remote_url' => null, 'remote_url' => null,
'preview_url' => $media->thumbnailUrl(), 'preview_url' => $media->thumbnailUrl(),

View file

@ -35,7 +35,8 @@ class User extends Authenticatable
protected $hidden = [ protected $hidden = [
'email', 'password', 'is_admin', 'remember_token', 'email', 'password', 'is_admin', 'remember_token',
'email_verified_at', '2fa_enabled', '2fa_secret', 'email_verified_at', '2fa_enabled', '2fa_secret',
'2fa_backup_codes', '2fa_setup_at', '2fa_backup_codes', '2fa_setup_at', 'deleted_at',
'updated_at'
]; ];
public function profile() public function profile()
@ -52,4 +53,9 @@ class User extends Authenticatable
{ {
return $this->hasOne(UserSetting::class); return $this->hasOne(UserSetting::class);
} }
public function receivesBroadcastNotificationsOn()
{
return 'App.User.'.$this->id;
}
} }

View file

@ -13,6 +13,10 @@ class Image
public $portrait; public $portrait;
public $thumbnail; public $thumbnail;
public $orientation; public $orientation;
public $acceptedMimes = [
'image/png',
'image/jpeg',
];
public function __construct() public function __construct()
{ {
@ -22,8 +26,8 @@ class Image
$this->landscape = $this->orientations()['landscape']; $this->landscape = $this->orientations()['landscape'];
$this->portrait = $this->orientations()['portrait']; $this->portrait = $this->orientations()['portrait'];
$this->thumbnail = [ $this->thumbnail = [
'width' => 293, 'width' => 640,
'height' => 293, 'height' => 640,
]; ];
$this->orientation = null; $this->orientation = null;
} }
@ -98,18 +102,22 @@ class Image
{ {
$path = $media->media_path; $path = $media->media_path;
$file = storage_path('app/'.$path); $file = storage_path('app/'.$path);
if (!in_array($media->mime, $this->acceptedMimes)) {
return;
}
$ratio = $this->getAspectRatio($file, $thumbnail); $ratio = $this->getAspectRatio($file, $thumbnail);
$aspect = $ratio['dimensions']; $aspect = $ratio['dimensions'];
$orientation = $ratio['orientation']; $orientation = $ratio['orientation'];
if ($media->mime === 'image/gif' && !$thumbnail) {
return;
}
try { try {
$img = Intervention::make($file)->orientate(); $img = Intervention::make($file)->orientate();
if($thumbnail) {
$img->crop($aspect['width'], $aspect['height']);
} else {
$img->resize($aspect['width'], $aspect['height'], function ($constraint) { $img->resize($aspect['width'], $aspect['height'], function ($constraint) {
$constraint->aspectRatio(); $constraint->aspectRatio();
}); });
}
$converted = $this->setBaseName($path, $thumbnail, $img->extension); $converted = $this->setBaseName($path, $thumbnail, $img->extension);
$newPath = storage_path('app/'.$converted['path']); $newPath = storage_path('app/'.$converted['path']);

View file

@ -50,7 +50,7 @@ return [
'charset' => 'utf8mb4', 'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci', 'collation' => 'utf8mb4_unicode_ci',
'prefix' => '', 'prefix' => '',
'strict' => true, 'strict' => false,
'engine' => null, 'engine' => null,
], ],

View file

@ -9,7 +9,7 @@ php artisan storage:link
php artisan migrate --force php artisan migrate --force
# Run a worker if it is set as embedded # Run a worker if it is set as embedded
if [ HORIZON_EMBED = true ]; then if [ $HORIZON_EMBED = true ]; then
php artisan horizon & php artisan horizon &
fi fi

View file

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateStoriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('stories', function (Blueprint $table) {
$table->increments('bigIncrements');
$table->bigInteger('profile_id')->unsigned();
$table->timestamp('published_at')->nullable();
$table->timestamp('expires_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('stories');
}
}

View file

@ -0,0 +1,33 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateStoryReactionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('story_reactions', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('profile_id')->unsigned()->nullable();
$table->string('reaction')->index();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('story_reactions');
}
}

View file

@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCollectionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('collections', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('profile_id')->unsigned()->nullable();
$table->string('title')->nullable();
$table->text('description')->nullable();
$table->boolean('is_nsfw')->default(false);
$table->string('visibility')->default('public')->index();
$table->timestamp('published_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('collections');
}
}

View file

@ -0,0 +1,38 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateDirectMessagesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('direct_messages', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('to_id')->unsigned()->index();
$table->bigInteger('from_id')->unsigned()->index();
$table->string('from_profile_ids')->nullable();
$table->boolean('group_message')->default(false);
$table->bigInteger('status_id')->unsigned()->integer();
$table->unique(['to_id', 'from_id', 'status_id']);
$table->timestamp('read_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('direct_messages');
}
}

View file

@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCollectionItemsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('collection_items', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('collection_id')->unsigned()->index();
$table->unsignedInteger('order')->nullable();
$table->string('object_type')->default('post')->index();
$table->bigInteger('object_id')->unsigned()->index();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('collection_items');
}
}

View file

@ -0,0 +1,28 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class UpdateStatusVisibilityDefaults extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement("ALTER TABLE statuses CHANGE COLUMN visibility visibility ENUM('public','unlisted','private','direct', 'draft') NOT NULL DEFAULT 'public'");
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View file

@ -0,0 +1,16 @@
<?php
return [
'about' => 'About',
'help' => 'Help',
'language' => 'Language',
'fediverse' => 'Fediverse',
'opensource' => 'Open Source',
'terms' => 'Terms',
'privacy' => 'Privacy',
'l10nWip' => 'Were still working on localization support',
'currentLocale' => 'Current locale',
'selectLocale' => 'Select from one of the supported languages',
];

View file

@ -0,0 +1,16 @@
<?php
return [
'about' => 'Environ',
'help' => 'Aidez-moi',
'language' => 'La langue',
'fediverse' => 'Fediverse',
'opensource' => 'Open Source',
'terms' => 'Termes',
'privacy' => 'Intimité',
'l10nWip' => 'Nous travaillons toujours sur le support de la localisation',
'currentLocale' => 'Locale actuelle',
'selectLocale' => 'Sélectionnez l\'une des langues prises en charge',
];

View file

@ -30,30 +30,33 @@
</div> </div>
</div> </div>
@php($reports = App\Report::whereNull('admin_seen')->count())
<div class="col-md-4"> <div class="col-md-4">
<div class="card"> <div class="card">
<div class="card-body text-center"> <div class="card-body text-center">
<p class="h2">{{App\Util\Lexer\PrettyNumber::convert(App\Report::whereNull('admin_seen')->count())}}</p> <p class="h2" title="{{$reports}}" data-toggle="tooltip">{{App\Util\Lexer\PrettyNumber::convert($reports)}}</p>
<p class="small text-uppercase font-weight-bold text-muted mb-0">Reports</p> <p class="small text-uppercase font-weight-bold text-muted mb-0">Reports</p>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
@php($statuses = App\Status::whereNull('in_reply_to_id')->whereNull('reblog_of_id')->count())
<div class="row mt-4"> <div class="row mt-4">
<div class="col-md-4"> <div class="col-md-4">
<div class="card"> <div class="card">
<div class="card-body text-center"> <div class="card-body text-center">
<p class="h2">{{App\Util\Lexer\PrettyNumber::convert(App\Status::whereNull('in_reply_to_id')->whereNull('reblog_of_id')->count())}}</p> <p class="h2" title="{{$statuses}}" data-toggle="tooltip">{{App\Util\Lexer\PrettyNumber::convert($statuses)}}</p>
<p class="small text-uppercase font-weight-bold text-muted mb-0">Statuses</p> <p class="small text-uppercase font-weight-bold text-muted mb-0">Statuses</p>
</div> </div>
</div> </div>
</div> </div>
@php($replies = App\Status::whereNotNull('in_reply_to_id')->count())
<div class="col-md-4"> <div class="col-md-4">
<div class="card"> <div class="card">
<div class="card-body text-center"> <div class="card-body text-center">
<p class="h2">{{App\Util\Lexer\PrettyNumber::convert(App\Status::whereNotNull('in_reply_to_id')->count())}}</p> <p class="h2" title="{{$replies}}" data-toggle="tooltip">{{App\Util\Lexer\PrettyNumber::convert($replies)}}</p>
<p class="small text-uppercase font-weight-bold text-muted mb-0">Replies</p> <p class="small text-uppercase font-weight-bold text-muted mb-0">Replies</p>
</div> </div>
</div> </div>

View file

@ -6,7 +6,7 @@
<div class="card mx-5"> <div class="card mx-5">
<div class="card-body p-5 text-center"> <div class="card-body p-5 text-center">
<h1>Whoops! Something went wrong.</h1> <h1>Whoops! Something went wrong.</h1>
<p class="mb-0 text-muted lead">Please try again, if this error keeps happening please contact an admin.</p> <p class="mb-0 text-muted lead">If you keep seeing this message, please contact an admin.</p>
<img src="/img/fred1.gif" class="img-fluid"> <img src="/img/fred1.gif" class="img-fluid">
</div> </div>
</div> </div>

View file

@ -0,0 +1,31 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
class LoginTest extends TestCase
{
/** @test */
public function view_login_page()
{
$response = $this->get('login');
$response->assertSuccessful()
->assertSee('Forgot Your Password?');
}
/** @test */
public function view_register_page()
{
if(true === config('pixelfed.open_registration')) {
$response = $this->get('register');
$response->assertSuccessful()
->assertSee('Register a new account');
} else {
$this->assertTrue(true);
}
}
}