Skip to content

Commit

Permalink
Added omboarding and changelog flows, added labels to quickaccess ico…
Browse files Browse the repository at this point in the history
…ns, added bulk install edgeapp icons
  • Loading branch information
paulotruta committed Nov 2, 2024
1 parent f9c8298 commit 16f84e7
Show file tree
Hide file tree
Showing 34 changed files with 1,737 additions and 501 deletions.
4 changes: 4 additions & 0 deletions src/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ services:
- '../src/Entity/'
- '../src/Kernel.php'

App\EventSubscriber\MiddlewareSubscriber:
tags:
- { name: kernel.event_subscriber }

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/public/assets/img/edgeapps/siyuan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/src/Attribute/RunMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Attribute;

#[\Attribute(\Attribute::TARGET_METHOD)]
class RunMiddleware
{
public function __construct(
public string $name
) {}
}
45 changes: 45 additions & 0 deletions src/src/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,51 @@ public function edgeapps(Request $request): JsonResponse
}

$data = $response;

} elseif ('install_bulk_edgeapps' == $data['op']) {
# Create a task to install all apps in the list
# But remove apps that are alredy installed

$apps_list = $this->edgeAppsHelper->getEdgeAppsList();
$installed_apps = [];
foreach ($apps_list as $app) {
if ($app['status']['description'] == 'on') {
$installed_apps[] = $app['id'];
}
}

// $data['ids'] is an array like ['id1', 'id2', ...]
// It should always have this format

$data['ids'] = array_diff($data['ids'], $installed_apps);

if (empty($data['ids'])) {
$response = [
'status' => 'error',
'message' => 'No apps to install',
];

return new JsonResponse($response);
}

$task = $this->taskFactory->createInstallBulkEdgeappsTask($data['ids']);
if (Task::STATUS_ERROR === $task->getStatus()) {
$response = [
'status' => 'error',
'message' => 'Task creation failed',
];

return new JsonResponse($response);
}

$this->entityManager->persist($task);
$this->entityManager->flush();

$response = [
'status' => 'executing',
'message' => 'Task created',
'task_id' => $task->getId(),
];
} else {
$data = [
'status' => 'error',
Expand Down
9 changes: 5 additions & 4 deletions src/src/Controller/BackupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace App\Controller;

use App\Attribute\RunMiddleware;
use App\Helper\BackupsHelper;
use App\Helper\DashboardHelper;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Controller\BaseController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

#[IsGranted('IS_AUTHENTICATED_FULLY')]
class BackupsController extends AbstractController
class BackupsController extends BaseController
{
private DashboardHelper $dashboardHelper;

protected DashboardHelper $dashboardHelper;
private BackupsHelper $backupsHelper;

public function __construct(
Expand All @@ -24,6 +24,7 @@ public function __construct(
$this->backupsHelper = $backupsHelper;
}

#[RunMiddleware('checkChangelogRedirect')]
#[Route('/backups', name: 'backups')]
public function index(): Response
{
Expand Down
51 changes: 51 additions & 0 deletions src/src/Controller/BaseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Controller;

use App\Helper\DashboardHelper;
use App\Repository\OptionRepository;
use App\Entity\Option;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

// Use in controllers:
abstract class BaseController extends AbstractController
{

protected DashboardHelper $dashboardHelper;

public function __construct(DashboardHelper $dashboardHelper)
{
$this->dashboardHelper = $dashboardHelper;
}

public function checkChangelogRedirect(): ?Response
{
$current_system_changelog_version = $this->dashboardHelper->getSystemChangelogVersion();

$last_seen_changelog_version = $this->dashboardHelper->getOptionValue('LAST_SEEN_CHANGELOG_VERSION') ?? '0';

if ($current_system_changelog_version != $last_seen_changelog_version) {
$this->dashboardHelper->setOptionValue('LAST_SEEN_CHANGELOG_VERSION', $current_system_changelog_version);
return $this->redirectToRoute('changelog-version', ['version' => $current_system_changelog_version]);
}

return null;
}

public function checkOnboardingRedirect(): ?Response
{
$onboarding_completed = $this->dashboardHelper->getOptionValue('ONBOARDING_COMPLETED') ?? 'no';

if ($onboarding_completed == 'no') {
$onboarding_completed = 'yes';
$this->dashboardHelper->setOptionValue('ONBOARDING_COMPLETED', $onboarding_completed);
return $this->redirectToRoute('hello');
}

return null;
}
}
89 changes: 89 additions & 0 deletions src/src/Controller/ChangelogController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace App\Controller;

use App\Controller\BaseController;
use App\Attribute\RunMiddleware;
use App\Entity\Task;
use App\Helper\BackupsHelper;
use App\Helper\DashboardHelper;
use App\Helper\EdgeAppsHelper;
use App\Helper\StorageHelper;
use App\Helper\SystemHelper;
use App\Repository\TaskRepository;
use App\Repository\OptionRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;


#[IsGranted('IS_AUTHENTICATED_FULLY')]
class ChangelogController extends AbstractController
{
private TaskRepository $taskRepository;
private OptionRepository $optionRepository;
private SystemHelper $systemHelper;
private EdgeAppsHelper $edgeAppsHelper;
private StorageHelper $storageHelper;
private BackupsHelper $backupsHelper;
protected DashboardHelper $dashboardHelper;

public function __construct(
TaskRepository $taskRepository,
OptionRepository $optionRepository,
SystemHelper $systemHelper,
EdgeAppsHelper $edgeAppsHelper,
StorageHelper $storageHelper,
DashboardHelper $dashboardHelper,
BackupsHelper $backupsHelper
) {
$this->taskRepository = $taskRepository;
$this->optionRepository = $optionRepository;
$this->systemHelper = $systemHelper;
$this->edgeAppsHelper = $edgeAppsHelper;
$this->storageHelper = $storageHelper;
$this->dashboardHelper = $dashboardHelper;
$this->backupsHelper = $backupsHelper;
}

#[Route('/changelog', name: 'latest-change-log')]
public function hello(): Response
{

$target_version = $this->dashboardHelper->getSystemChangelogVersion();

# If LAST_SEEN_CHANGELOG_VERSION is not set, redirect to the changelog page.

return $this->render('changelog/' . $target_version . '.html.twig', [
// 'controller_title' => 'Dashboard',
// 'controller_subtitle' => 'Welcome back!',
// 'container_system_uptime' => $this->getSystemUptimeContainerVar(),
// 'container_working_edgeapps' => $this->getWorkingEdgeAppsContainerVars(),
// 'container_storage_summary' => $this->getStorageSummaryContainerVars(),
// 'container_backups_last_run' => $this->getLastBackupRunContainerVar(),
// 'container_actions_overview' => $this->getActionsOverviewContainerVars(),
// 'container_apps_quickaccess' => $this->getQuickEdgeAppsAccessContainerVars(),
'target_version' => $target_version,
'dashboard_settings' => $this->dashboardHelper->getSettings(),
]);
}

#[Route('/changelog/{version}', name: 'changelog-version')]
public function changelog_version(string $version): Response
{
return $this->render('changelog/' . $version . '.html.twig', [
// 'controller_title' => 'Dashboard',
// 'controller_subtitle' => 'Welcome back!',
// 'container_system_uptime' => $this->getSystemUptimeContainerVar(),
// 'container_working_edgeapps' => $this->getWorkingEdgeAppsContainerVars(),
// 'container_storage_summary' => $this->getStorageSummaryContainerVars(),
// 'container_backups_last_run' => $this->getLastBackupRunContainerVar(),
// 'container_actions_overview' => $this->getActionsOverviewContainerVars(),
// 'container_apps_quickaccess' => $this->getQuickEdgeAppsAccessContainerVars(),
'target_version' => $version,
'dashboard_settings' => $this->dashboardHelper->getSettings(),
]);
}

}
48 changes: 7 additions & 41 deletions src/src/Controller/EdgeAppsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Controller;

use App\Attribute\RunMiddleware;
use App\Entity\Option;
use App\Entity\Task;
use App\Factory\TaskFactory;
Expand All @@ -10,22 +11,22 @@
use App\Helper\SystemHelper;
use App\Repository\OptionRepository;
use App\Repository\TaskRepository;
use App\Controller\BaseController;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

#[IsGranted('IS_AUTHENTICATED_FULLY')]
class EdgeAppsController extends AbstractController
class EdgeAppsController extends BaseController
{
private OptionRepository $optionRepository;
private EntityManagerInterface $entityManager;
private EdgeAppsHelper $edgeAppsHelper;
private SystemHelper $systemHelper;
private TaskFactory $taskFactory;
private DashboardHelper $dashboardHelper;
protected DashboardHelper $dashboardHelper;

private TaskRepository $taskRepository;

Expand Down Expand Up @@ -71,50 +72,15 @@ public function __construct(
$this->dashboardHelper = $dashboardHelper;
}

#[RunMiddleware('checkChangelogRedirect')]
#[Route('/edgeapps', name: 'edgeapps')]
public function index(): Response
{
$framework_ready = false;
$tunnel_on = false;

$apps_list = $this->edgeAppsHelper->getEdgeAppsList();
$ongoing_tasks = $this->taskRepository->findByOngoing();

$app_tasks = [
TaskFactory::INSTALL_EDGEAPP,
TaskFactory::REMOVE_EDGEAPP,
TaskFactory::START_EDGEAPP,
TaskFactory::STOP_EDGEAPP,
TaskFactory::SET_EDGEAPP_OPTIONS,
TaskFactory::ENABLE_ONLINE,
TaskFactory::DISABLE_ONLINE,
];

if (!empty($ongoing_tasks)) {
$ongoing_apps_and_statuses = [];

foreach ($ongoing_tasks as $ongoing_task) {
$task_code = $ongoing_task->getTask();
if (in_array($task_code, $app_tasks)) {
$app_id = json_decode($ongoing_task->getArgs(), true)['id'];
$ongoing_apps_and_statuses[$app_id] = [
'task_code' => $task_code,
'task_id' => $ongoing_task->getId(),
];
}
}

foreach ($apps_list as $app_key => $app) {
$app_id = $app['id'];
if (!empty($ongoing_apps_and_statuses[$app_id])) {
$apps_list[$app_key]['status'] = [
'id' => 4,
'description' => $ongoing_apps_and_statuses[$app_id]['task_code'],
'task_id' => $ongoing_apps_and_statuses[$app_id]['task_id'],
];
}
}
}
$apps_list = $this->edgeAppsHelper->getEdgeAppsList($fetchOngoingStatuses = true, $fetchOngoingStatuses = true);
$app_tasks = $this->taskRepository->findByOngoing();

if (!empty($apps_list)) {
$tunnel_on_option = $this->optionRepository->findOneBy(['name' => 'BOOTNODE_TOKEN']) ?? new Option();
Expand Down
Loading

0 comments on commit 16f84e7

Please sign in to comment.