Hi there!
I’m new to Cockpit, and currently setting up an addon to “integrate” Google Drive (dashboard widget / drive picker + services like uploading/retrieving files to/from google drive, generating/updating accouting Sheets; generating Google Docs from templates --like invoices…).
For now, I have two silly questions:
1/ how in all heavens do you make your additionnal assets (css and js) load and work?
I’ve looked up how other addons did it; mimicked them; but for an unknown reason it’s not working on my side. I’m missing something obviously.
bootstrap.php:
$app->path('googledrive', 'addons/GoogleDrive/');
$this->module("cockpit")->extend([]);
include_once(__DIR__ . '/admin.php');
in admin.php:
require_once(__DIR__ . '/Controller/googleservices.php');
$app->on('admin.init', function() {}, 0);
$app->on("admin.dashboard.widgets", function($widgets) {
if ($this->module('cockpit')->hasaccess('cockpit', 'GoogleDrive')) {
$this->helper('admin')->addAssets('googledrive:assets/js/googledrive.js');
$this->helper('admin')->addAssets('googledrive:assets/css/googledrive.css');
$title = 'GoogleDrive yo';
$gclient = new GoogleServices();
$gat = $gclient->getgAccessToken();
$widgets[] = [
"name" => 'GoogleDrive',
"content" => $this->view("googledrive:views/partials/widget.php", compact('title','gat')),
"area" => 'main'
];
}
}, 100);
$app('admin')->init();
I’ve tried direct url; I’ve tried adding @route… nothing works.
(I actually struggle quite a lot with routes; I wanted to make a proper “cockpit” class with public function index()
but loading the Google Api from there would fail (bad route); so for now it’s just a good old __construct()
…)
2/ How do you access data contained in a specific singleton? Do you make an… api call?
Reasons: I would like to retrieve the google .json credentials file (service account) from a “user config” singleton. I would prefer to avoid the user to manually edit the config.yaml.
Thanks!
(I will obviously share the addon once done!)