Added My apps page, it show Purchase and installed app
This commit is contained in:
29
app/Http/Controllers/Modules/My.php
Normal file
29
app/Http/Controllers/Modules/My.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Modules;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\Modules;
|
||||
use App\Models\Module\Module;
|
||||
use Illuminate\Routing\Route;
|
||||
|
||||
class My extends Controller
|
||||
{
|
||||
use Modules;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->checkApiToken();
|
||||
|
||||
$purchased = $this->getMyModules();
|
||||
$modules = $this->getInstalledModules();
|
||||
$installed = Module::all()->pluck('status', 'alias')->toArray();
|
||||
|
||||
return view('modules.my.index', compact('purchased', 'modules', 'installed'));
|
||||
}
|
||||
}
|
48
app/Listeners/Updates/Version126.php
Normal file
48
app/Listeners/Updates/Version126.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Updates;
|
||||
|
||||
use App\Events\UpdateFinished;
|
||||
use App\Models\Auth\Role;
|
||||
use App\Models\Auth\Permission;
|
||||
|
||||
class Version126 extends Listener
|
||||
{
|
||||
const ALIAS = 'core';
|
||||
|
||||
const VERSION = '1.2.6';
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(UpdateFinished $event)
|
||||
{
|
||||
// Check if should listen
|
||||
if (!$this->check($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create permission
|
||||
$permission = Permission::firstOrCreate([
|
||||
'name' => 'read-modules-my',
|
||||
'display_name' => 'Read Modules My',
|
||||
'description' => 'Read Modules My',
|
||||
]);
|
||||
|
||||
// Attach permission to roles
|
||||
$roles = Role::all();
|
||||
|
||||
foreach ($roles as $role) {
|
||||
$allowed = ['admin', 'manager'];
|
||||
|
||||
if (!in_array($role->name, $allowed)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$role->attachPermission($permission);
|
||||
}
|
||||
}
|
||||
}
|
@@ -23,6 +23,7 @@ class EventServiceProvider extends ServiceProvider
|
||||
'App\Listeners\Updates\Version113',
|
||||
'App\Listeners\Updates\Version119',
|
||||
'App\Listeners\Updates\Version120',
|
||||
'App\Listeners\Updates\Version126',
|
||||
],
|
||||
'Illuminate\Auth\Events\Login' => [
|
||||
'App\Listeners\Auth\Login',
|
||||
|
@@ -78,6 +78,45 @@ trait Modules
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getMyModules($data = [])
|
||||
{
|
||||
$response = $this->getRemote('apps/my', 'GET', $data);
|
||||
|
||||
if ($response && ($response->getStatusCode() == 200)) {
|
||||
return json_decode($response->getBody())->data;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getInstalledModules($data = [])
|
||||
{
|
||||
$company_id = session('company_id');
|
||||
|
||||
$cache = 'installed.' . $company_id . '.module';
|
||||
|
||||
$installed = Cache::get($cache);
|
||||
|
||||
if ($installed) {
|
||||
return $installed;
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
$modules = Module::all();
|
||||
|
||||
foreach ($modules as $module) {
|
||||
$result = $this->getModule($module->alias);
|
||||
|
||||
if ($result) {
|
||||
$installed[] = $result;
|
||||
}
|
||||
}
|
||||
|
||||
Cache::put($cache, $installed, Date::now()->addHour(6));
|
||||
|
||||
return $installed;
|
||||
}
|
||||
|
||||
public function getPaidModules($data = [])
|
||||
{
|
||||
$response = $this->getRemote('apps/paid', 'GET', $data);
|
||||
|
Reference in New Issue
Block a user