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.
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.
Code inside admin.php is only for backend access, so don’t load it if you don’t need it. The name has nothing to do with the “admin” group permission.
if (COCKPIT_ADMIN_CP) include_once(__DIR__ . '/admin.php');
Don’t start with widgets, if you want to learn Cockpit. Create pages and routes, call them directly in your browser to see the json responses. If your core logic works, think about widgets. Be aware, that widgets have a drag event by default.