mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 00:02:15 +00:00
dashboard include
This commit is contained in:
56
app/Http/Controllers/Admin/DashboardController.php
Normal file
56
app/Http/Controllers/Admin/DashboardController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\FileManagerFile;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\UsersCollection;
|
||||
use App\Services\StripeService;
|
||||
use App\User;
|
||||
use ByteUnits\Metric;
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Cashier\Subscription;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
/**
|
||||
* DashboardController constructor.
|
||||
*/
|
||||
public function __construct(StripeService $stripe)
|
||||
{
|
||||
$this->stripe = $stripe;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Get total users
|
||||
$total_users = User::all()->count();
|
||||
|
||||
// Get total used space
|
||||
$total_used_space = FileManagerFile::all()->map(function ($item) {
|
||||
return (int)$item->getRawOriginal('filesize');
|
||||
})->sum();
|
||||
|
||||
// Get total premium users
|
||||
$total_premium_users = Subscription::where('stripe_status', 'active')->get()->count();
|
||||
|
||||
return [
|
||||
'app_version' => config('vuefilemanager.version'),
|
||||
'total_users' => $total_users,
|
||||
'total_used_space' => Metric::bytes($total_used_space)->format(),
|
||||
'total_premium_users' => $total_premium_users,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the newest users
|
||||
*
|
||||
* @return UsersCollection
|
||||
*/
|
||||
public function new_registrations()
|
||||
{
|
||||
return new UsersCollection(
|
||||
User::take(5)->orderByDesc('created_at')->get()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\GatewayCollection;
|
||||
use App\Http\Resources\GatewayResource;
|
||||
use App\Http\Resources\InvoiceCollection;
|
||||
use App\Invoice;
|
||||
use App\PaymentGateway;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class GatewayController extends Controller
|
||||
{
|
||||
/**
|
||||
* Get all payment gateways
|
||||
*
|
||||
* @return GatewayCollection
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return new GatewayCollection(PaymentGateway::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single payment gateway by slug
|
||||
*
|
||||
* @param $slug
|
||||
* @return GatewayResource
|
||||
*/
|
||||
public function show($slug)
|
||||
{
|
||||
$gateway = PaymentGateway::where('slug', $slug)->firstOrFail();
|
||||
|
||||
return new GatewayResource($gateway);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single payment gateway by slug
|
||||
*
|
||||
* @param $slug
|
||||
* @return InvoiceCollection
|
||||
*/
|
||||
public function show_transactions($slug)
|
||||
{
|
||||
return new InvoiceCollection(
|
||||
Invoice::where('provider', $slug)->get()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update payment gateway options
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $slug
|
||||
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $slug)
|
||||
{
|
||||
// TODO: validation request
|
||||
|
||||
$gateway = PaymentGateway::where('slug', $slug)->first();
|
||||
|
||||
// Update text data
|
||||
$gateway->update(make_single_input($request));
|
||||
|
||||
return response('Saved!', 204);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ use App\Services\StripeService;
|
||||
use App\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Laravel\Cashier\Subscription;
|
||||
use Rinvex\Subscriptions\Models\PlanFeature;
|
||||
|
||||
class PlanController extends Controller
|
||||
@@ -126,10 +127,7 @@ class PlanController extends Controller
|
||||
*/
|
||||
public function subscribers($id)
|
||||
{
|
||||
$subscribers = app('rinvex.subscriptions.plan')
|
||||
->find($id)
|
||||
->subscriptions
|
||||
->pluck('user_id');
|
||||
$subscribers = Subscription::where('stripe_plan', $id)->pluck('user_id');
|
||||
|
||||
return new UsersCollection(
|
||||
User::findMany($subscribers)
|
||||
|
||||
@@ -106,7 +106,7 @@ class SetupWizardController extends Controller
|
||||
|
||||
// Store database credentials
|
||||
$database_credentials->each(function ($col) {
|
||||
$this->setEnvironmentValue($col['name'], $col['value']);
|
||||
setEnvironmentValue($col['name'], $col['value']);
|
||||
});
|
||||
|
||||
// Set database connection
|
||||
@@ -161,8 +161,8 @@ class SetupWizardController extends Controller
|
||||
$client = \DB::table('oauth_clients')->where('name', '=', 'vuefilemanager')->first();
|
||||
|
||||
// Set passport client to .env
|
||||
$this->setEnvironmentValue('PASSPORT_CLIENT_ID', $client->id);
|
||||
$this->setEnvironmentValue('PASSPORT_CLIENT_SECRET', $client->secret);
|
||||
setEnvironmentValue('PASSPORT_CLIENT_ID', $client->id);
|
||||
setEnvironmentValue('PASSPORT_CLIENT_SECRET', $client->secret);
|
||||
|
||||
// Clear cache
|
||||
Artisan::call('config:clear');
|
||||
@@ -208,19 +208,13 @@ class SetupWizardController extends Controller
|
||||
]);
|
||||
|
||||
// Set stripe credentials to .env
|
||||
$this->setEnvironmentValue('CASHIER_CURRENCY', $request->currency);
|
||||
$this->setEnvironmentValue('STRIPE_KEY', $request->key);
|
||||
$this->setEnvironmentValue('STRIPE_SECRET', $request->secret);
|
||||
$this->setEnvironmentValue('STRIPE_WEBHOOK_SECRET', $request->webhookSecret);
|
||||
|
||||
// Store options
|
||||
$settings->each(function ($col) {
|
||||
Setting::updateOrCreate(['name' => $col['name']], $col);
|
||||
});
|
||||
setEnvironmentValue('CASHIER_CURRENCY', $request->currency);
|
||||
setEnvironmentValue('STRIPE_KEY', $request->key);
|
||||
setEnvironmentValue('STRIPE_SECRET', $request->secret);
|
||||
setEnvironmentValue('STRIPE_WEBHOOK_SECRET', $request->webhookSecret);
|
||||
|
||||
// Clear cache
|
||||
Artisan::call('config:clear');
|
||||
//Artisan::call('config:cache');
|
||||
|
||||
return response('Done', 200);
|
||||
}
|
||||
@@ -427,7 +421,7 @@ class SetupWizardController extends Controller
|
||||
|
||||
// Store storage driver options
|
||||
$storage->each(function ($col) {
|
||||
$this->setEnvironmentValue($col['name'], $col['value']);
|
||||
setEnvironmentValue($col['name'], $col['value']);
|
||||
});
|
||||
|
||||
// Get options
|
||||
@@ -460,12 +454,11 @@ class SetupWizardController extends Controller
|
||||
|
||||
// Store mail options
|
||||
$mail->each(function ($col) {
|
||||
$this->setEnvironmentValue($col['name'], $col['value']);
|
||||
setEnvironmentValue($col['name'], $col['value']);
|
||||
});
|
||||
|
||||
// Clear cache
|
||||
Artisan::call('config:clear');
|
||||
//Artisan::call('config:cache');
|
||||
|
||||
return response('Done', 200);
|
||||
}
|
||||
@@ -545,10 +538,12 @@ class SetupWizardController extends Controller
|
||||
{
|
||||
// Validate request
|
||||
$request->validate([
|
||||
'email' => 'required|string|email|unique:users',
|
||||
'password' => 'required|string|min:6|confirmed',
|
||||
'name' => 'required|string',
|
||||
'avatar' => 'sometimes|file',
|
||||
'email' => 'required|string|email|unique:users',
|
||||
'password' => 'required|string|min:6|confirmed',
|
||||
'name' => 'required|string',
|
||||
'purchase_code' => 'required|string',
|
||||
'license' => 'required|string',
|
||||
'avatar' => 'sometimes|file',
|
||||
]);
|
||||
|
||||
// Store avatar
|
||||
@@ -580,6 +575,18 @@ class SetupWizardController extends Controller
|
||||
'value' => 1,
|
||||
]);
|
||||
|
||||
// Store License
|
||||
Setting::create([
|
||||
'name' => 'license',
|
||||
'value' => $request->license,
|
||||
]);
|
||||
|
||||
// Store Purchase Code
|
||||
Setting::create([
|
||||
'name' => 'license',
|
||||
'value' => $request->purchase_code,
|
||||
]);
|
||||
|
||||
// Retrieve access token
|
||||
$response = Route::dispatch(self::make_login_request($request));
|
||||
|
||||
@@ -613,23 +620,4 @@ class SetupWizardController extends Controller
|
||||
|
||||
return Request::create(url('/oauth/token'), 'POST', $request->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set environment value
|
||||
*
|
||||
* @param $key
|
||||
* @param $value
|
||||
*/
|
||||
public function setEnvironmentValue($key, $value)
|
||||
{
|
||||
$env_path = app()->environmentFilePath();
|
||||
|
||||
$escaped = preg_quote('=' . env($key), '/');
|
||||
|
||||
file_put_contents($env_path, preg_replace(
|
||||
"/^{$key}{$escaped}/m",
|
||||
$key . '=' . $value,
|
||||
file_get_contents($env_path)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,83 +3,105 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Setting;
|
||||
use Artisan;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SettingController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
* Get table content
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
public function show(Request $request) {
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
$column = $request->get('column');
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
if (strpos($column, '|') !== false) {
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Setting $setting
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Setting $setting)
|
||||
{
|
||||
//
|
||||
}
|
||||
$columns = explode('|', $column);
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Setting $setting
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Setting $setting)
|
||||
{
|
||||
//
|
||||
return Setting::whereIn('name', $columns)->pluck('value', 'name');
|
||||
}
|
||||
|
||||
return Setting::where('name', $column)->pluck('value', 'name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Setting $setting
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Setting $setting)
|
||||
public function update(Request $request)
|
||||
{
|
||||
//
|
||||
// Store image if exist
|
||||
if ($request->hasFile($request->name)) {
|
||||
|
||||
// Store image
|
||||
$image_path = store_system_image($request->file($request->name), 'system');
|
||||
|
||||
// Find and update image path
|
||||
Setting::updateOrCreate(['name' => $request->name], [
|
||||
'value' => $image_path
|
||||
]);
|
||||
|
||||
return response('Done', 204);
|
||||
}
|
||||
|
||||
// Find and update variable
|
||||
Setting::updateOrCreate(['name' => $request->name], [
|
||||
'value' => $request->value
|
||||
]);
|
||||
|
||||
return response('Done', 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
* Set new email credentials to .env file
|
||||
*
|
||||
* @param \App\Setting $setting
|
||||
* @return \Illuminate\Http\Response
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Setting $setting)
|
||||
{
|
||||
//
|
||||
public function set_email(Request $request) {
|
||||
|
||||
// Get options
|
||||
$mail = collect([
|
||||
[
|
||||
'name' => 'MAIL_DRIVER',
|
||||
'value' => $request->input('driver'),
|
||||
],
|
||||
[
|
||||
'name' => 'MAIL_HOST',
|
||||
'value' => $request->input('host'),
|
||||
],
|
||||
[
|
||||
'name' => 'MAIL_PORT',
|
||||
'value' => $request->input('port'),
|
||||
],
|
||||
[
|
||||
'name' => 'MAIL_USERNAME',
|
||||
'value' => $request->input('username'),
|
||||
],
|
||||
[
|
||||
'name' => 'MAIL_PASSWORD',
|
||||
'value' => $request->input('password'),
|
||||
],
|
||||
[
|
||||
'name' => 'MAIL_ENCRYPTION',
|
||||
'value' => $request->input('encryption'),
|
||||
],
|
||||
]);
|
||||
|
||||
// Store mail options
|
||||
$mail->each(function ($col) {
|
||||
setEnvironmentValue($col['name'], $col['value']);
|
||||
});
|
||||
|
||||
// Clear cache
|
||||
Artisan::call('config:clear');
|
||||
|
||||
return response('Done', 204);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,29 @@ use App\Share;
|
||||
use ByteUnits\Metric;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Intervention\Image\ImageManagerStatic as Image;
|
||||
|
||||
/**
|
||||
* Set environment value
|
||||
*
|
||||
* @param $key
|
||||
* @param $value
|
||||
*/
|
||||
function setEnvironmentValue($key, $value)
|
||||
{
|
||||
$env_path = app()->environmentFilePath();
|
||||
|
||||
$escaped = preg_quote('=' . env($key), '/');
|
||||
|
||||
file_put_contents($env_path, preg_replace(
|
||||
"/^{$key}{$escaped}/m",
|
||||
$key . '=' . $value,
|
||||
file_get_contents($env_path)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get invoice number
|
||||
*
|
||||
@@ -27,6 +45,10 @@ function get_invoice_number()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget many cache keys at once
|
||||
* @param $cache
|
||||
*/
|
||||
function cache_forget_many($cache)
|
||||
{
|
||||
foreach ($cache as $item) {
|
||||
|
||||
@@ -52,8 +52,8 @@ class InvoiceAdminResource extends JsonResource
|
||||
'id' => (string)$user->id,
|
||||
'type' => 'user',
|
||||
'attributes' => [
|
||||
'name' => $user->name,
|
||||
'avatar' => $user->avatar,
|
||||
'name' => $user->name,
|
||||
'avatar' => $user->avatar,
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
@@ -26,7 +26,7 @@ class InvoiceResource extends JsonResource
|
||||
'customer' => $this->customer,
|
||||
'total' => $this->total(),
|
||||
'currency' => $this->currency,
|
||||
'created_at_formatted' => format_date($this->date()),
|
||||
'created_at_formatted' => format_date($this->date(), '%d. %B. %Y'),
|
||||
'created_at' => $this->created,
|
||||
'order' => $this->number,
|
||||
'user_id' => $user ? $user->id : null,
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Laravel\Cashier\Cashier;
|
||||
use Laravel\Cashier\Subscription;
|
||||
|
||||
class PlanResource extends JsonResource
|
||||
{
|
||||
@@ -14,18 +16,22 @@ class PlanResource extends JsonResource
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
// Get subscribers
|
||||
$subscriber_count = Subscription::where('stripe_plan', $this['plan']['id'])->get();
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'id' => $this['plan']['id'],
|
||||
'type' => 'plans',
|
||||
'attributes' => [
|
||||
'subscribers' => $this['plan']['aggregate_usage'],
|
||||
'status' => $this['plan']['active'],
|
||||
'subscribers' => $subscriber_count->count(),
|
||||
'status' => $this['plan']['active'] ? 1 : 0,
|
||||
'name' => $this['product']['name'],
|
||||
'description' => $this['product']['description'],
|
||||
'price' => $this['plan']['amount'],
|
||||
'price_formatted' => Cashier::formatAmount($this['plan']['amount']),
|
||||
'capacity_formatted' => format_gigabytes($this['product']['metadata']['capacity']),
|
||||
'capacity' => $this['product']['metadata']['capacity'],
|
||||
'capacity' => (int) $this['product']['metadata']['capacity'],
|
||||
'created_at_formatted' => format_date($this['plan']['created']),
|
||||
'created_at' => $this['plan']['created'],
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user