All Projects → pauloamgomes → CockpitCMS-Helpers

pauloamgomes / CockpitCMS-Helpers

Licence: MIT license
Cockpit CMS Addon with a set of useful helpers (that alone don't justify a new Addon).

Programming Languages

PHP
23972 projects - #3 most used programming language
hack
652 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to CockpitCMS-Helpers

cockpit-sql-driver
SQL Driver for Cockpit CMS
Stars: ✭ 28 (-28.21%)
Mutual labels:  addon, cockpit-cms
garrysmod-chatsounds
Community Uploaded Ingame Chat Reaction Sounds
Stars: ✭ 68 (+74.36%)
Mutual labels:  addon
What Have You Made Today
Chrome & FireFox extension to replace the default home page. What have you made today?
Stars: ✭ 223 (+471.79%)
Mutual labels:  addon
Bforartists
Bforartists is a fork of the popular 3D software Blender, with the goal to improve the UI.
Stars: ✭ 240 (+515.38%)
Mutual labels:  addon
Keyboard Layout Editor For Blender
Allows you to import keyboard layouts into blender and render them in 3d
Stars: ✭ 224 (+474.36%)
Mutual labels:  addon
addon-vscode-remote
VSCode Remote - Home Assistant Community Add-ons
Stars: ✭ 35 (-10.26%)
Mutual labels:  addon
Addon Smart Knobs
🧠 This Storybook plugin uses @storybook/addon-knobs but creates the knobs automatically based on PropTypes.
Stars: ✭ 215 (+451.28%)
Mutual labels:  addon
ember-window-messenger
This aims to be an simple window postMessage services provider.
Stars: ✭ 17 (-56.41%)
Mutual labels:  addon
newhackbar
A sitebar that helps pentesters to perform manual web security testing inside their browser. This addon is written in webextension and alternatives to the XUL version of original Hackbar.
Stars: ✭ 42 (+7.69%)
Mutual labels:  addon
The lightmapper
Fast and easy baked GI Lightmaps for Blender and Cycles
Stars: ✭ 233 (+497.44%)
Mutual labels:  addon
Elvui
ElvUI for World of Warcraft - Wrath of the Lich King (3.3.5a)
Stars: ✭ 229 (+487.18%)
Mutual labels:  addon
Ember Font Awesome
ember-cli addon for using Font Awesome icons in Ember apps
Stars: ✭ 225 (+476.92%)
Mutual labels:  addon
LambsDanger
AI enhancement mod for Arma 3
Stars: ✭ 88 (+125.64%)
Mutual labels:  addon
Gamestarter
🎮 Retrogaming kodi add-on repository for LibreELEC
Stars: ✭ 222 (+469.23%)
Mutual labels:  addon
addon-magicmirror
MagicMirror² - Home Assistant Community Add-ons
Stars: ✭ 40 (+2.56%)
Mutual labels:  addon
Cartographer
A GPU powered Terrain editor and renderer for Godot Engine
Stars: ✭ 216 (+453.85%)
Mutual labels:  addon
Godottie
A simple Text Interface Engine to control text output (like in a RPG dialogue) for Godot.
Stars: ✭ 230 (+489.74%)
Mutual labels:  addon
storybook-xstate-addon
A storybook addon to assist with writing stories that rely on xstate
Stars: ✭ 48 (+23.08%)
Mutual labels:  addon
snoozz-tab-snoozing
A Web Extension to declutter windows by snoozing tabs for later
Stars: ✭ 105 (+169.23%)
Mutual labels:  addon
TA-bigfix
Splunk technical add-on (TA) for ingesting BigFix client, relay, and server logs. Includes REST inputs for ingesting assets, relevant fixlets, action summaries, and analysis results.
Stars: ✭ 15 (-61.54%)
Mutual labels:  addon

Helpers Addon for CMS

This addon combines a set of features that would improve the main functionality of the Cockpit CMS. The idea is to be including new helpers as they are required.

Helpers

The current implementation provides:

Password reset

A CLI command that permits to reset the password of an user, e.g.:

./cp password --user "admin" --pass "admin"

Token API keys reset

A CLI command that permits to reset the tokens. By Default Cockpit has one "master" and one or more "special" keys.

Set the master key

./cp reset-api --name master --key 7e4c32f0546317bb8a3ec0166fa63c
  API key master set to 7e4c32f0546317bb8a3ec0166fa63c

Generate a new master key

./cp reset-api --name master
  API key master set to 7e4c32f0546317bb8a3ec0166fa63c

Set "special" key at position 1 (first entry of special keys)

./cp reset-api --name special --number 1
  API key special set to 7e4c32f0546317bb8a3ec0166fa63c

Generate a new "special" key for position 1

./cp reset-api --name special --number 1
  API key special set to 7e4c32f0546317bb8a3ec0166fa63c

Singleton data export/import CLI command

A CLI command that permits to export and import singleton data, e.g.:

$ ./cp export-singleton --name settings

Exporting data from singleton settings
Singleton settings exported to #storage:exports/singletons/settings.json - 4014 bytes written

To import just run the import-singleton command:

$ ./cp import-singleton --name settings
Singleton settings data imported from #storage:exports/singletons/settings.json

Notes: The #storage:exports/singletons folder is always used for exporting/importing.

Collection data export/import CLI command

A CLI command that permits to export and import collection data, e.g.:

./cp export-collection --name posts

Exporting collection posts (2 entries) to #storage:exports/collections/posts.json
Collection post exported to #storage:exports/collections/posts.json - 4014 bytes written

To import just run the import-collection command:

$ ./cp import-collection --name posts
  Importing collection posts (2 entries)
Imported 5c12ef4746eee8004a7a7b72 (insert)
Imported 5c14dd4746eee801bc2002c3 (insert)
Collection posts import done. Imported 2 entries

If the entries already exists they will be imported as a new revision:

$ ./cp import-collection --name posts
  Importing collection posts (2 entries)
Imported 5c12ef4746eee8004a7a7b72 (update)
Imported 5c14dd4746eee801bc2002c3 (update)
Collection posts import done. Imported 2 entries

Form data export/import CLI command

A CLI command that permits to export and import form data, e.g.:

./cp export-form --name submissions

Exporting form posts (2 entries) to #storage:exports/forms/submissions.json
Form post exported to #storage:exports/forms/submissions.json - 4014 bytes written

To import just run the import-form command:

$ ./cp import-form --name submissions
  Importing form submissions (2 entries)
Imported 5c12ef4746eee8004a7a7b72 (insert)
Imported 5c14dd4746eee801bc2002c3 (insert)
Form submissions import done. Imported 2 entries

Notes: The #storage:exports/collections folder is always used for exporting/importing.

Better handling of collection and singletons structure changes

Cockpit doesn't seem to map any changes in the structure of collections or singletons (e.g. removal of a field) in the data values. So if we remove a field the existing entries will not change and the field value is still returned by the API.

The addon implements two hooks that handle the problem:

  • collections.save.after - when the entry is saved and if a change is detected (existing data contains fields that are not in the collection structure anymore) the entry is deleted and inserted again (the id will not change). The main reason for delete and delete resides in the fact that Cockpit db update does a merge of the updated data with the existing data.
  • singleton.saveData.before - for the singletons is a bit more simple, we only need to confirm if the data changed and if so we remove the old fields.

That validation only takes place if its defined in the helpers global configuration as below:

helpers:
  checkSchema: true

Since the collection hooks will require a manual save of the collection entries, a CLI command was created to perform the update operation against all entries of a collection:

$ ./cp update-collection --name posts

Collection 'posts' - Updating fields...
Entry 5c1b8fb6cad42d03f72ab442 updated.
Done! 1 entries updated.

Addon install CLI command

The main idea behind an addon install command is to provide the possibility to include in the addon folder exported data (e.g. a singleton structure, a collection structure and entries, etc..). Let's imagine we are working in an bunch of core data structures that we need to put in place everytime we reinstall cockpit (or we have someone in the team starting), for example:

  • A settings singleton
  • A page collection

So we can create an addon (e.g. MySiteBase) that will have an export of above data structures and corresponding data. We can define our structure in the addon folder (e.g. addons/MySiteBase/install), in an addons/MySiteBase/info.yaml file:

name: MySiteBase
description: Provides core features for MySite
version: 0.1
install:
  singletons:
      - name: settings
        source: install/settings.singleton.php
        data: install/settings.json
  collections:
      - name: page
        source: install/page.collection.php
        rules:
          - create: install/rules/page.create.php
          - delete: install/rules/page.delete.php
          - read: install/rules/page.read.php
          - update: install/rules/page.update.php
        data: install/page.json
  customStorage:
      - source: install/myfile1.php
        target: "mycustomfolder/myfile1.php"
      - source: install/myfile2.php
        target: "mycustomfolder/myfile2.php"

So using above addon definition we can provide some context to the install CLI command and we can run:

$ ./cp install --name MySiteBase

Above command will create the data structures (Singletons and Collections) and correspondind data (Singleton data and Collection entries):

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Cockpit CMS Addon installer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Processing singletons...
 Installing singleton settings from /var/www/html/addons/MySiteBase/install/settings.singleton.php
* Singleton 'settings' created.
* Singleton 'settings' data imported.
Processing collections...
 Installing collection page from /var/www/html/addons/MySiteBase/install/page.collection.php
* Collection 'page' created.
 Installing collection page rules
* Collection 'page' rule 'create' created.
* Collection 'page' rule 'delete' created.
* Collection 'page' rule 'read' created.
* Collection 'page' rule 'update' created.
 Importing collection page (2 entries)
* Imported collection 'page' entry -> _id:5c12ef4746eee8004a7a7b72 (update)
* Imported collection 'page' entry -> _id:5c14dd4746eee801bc2002c3 (update)
Collection page import done. Imported 2 entries
Processing custom storage...
 Importing file into /var/www/html/storage/mycustomfolder/myfile1.php
* File '/var/www/html/storage/mycustomfolder/myfile1.php' created.
 Importing file into /var/www/html/storage/mycustomfolder/myfile2.php
* File '/var/www/html/storage/mycustomfolder/myfile2.php' created.

If the data structures are already installed we can force an overwrite/update by using the --force param:

$ ./cp install --name MySiteBase --force

@todo: Include in the install process Forms, Assets and custom operations.

JSON preview/live edit of collection entries and singletons data

A JSON link on each collection entry and singleton data sidebar, so we can access the JSON that will be returned from the API directly from the form page, e.g.:

JSON Preview/Live edit

The JSON can be changed directly in the editor and changes will be reflected in the form.

A view and edit permission is available for non admin users, e.g.:

groups:
  editor:
    helpers:
      jsonview: true
      jsonedit: true

Cockpit introduced recently in the core an option to inspect the entry json, however it doesn't provide yet editing capabilities.

Environment indicator

A simple mechanism to provide a visual feedback regarding the environment we are working, this can be useful to prevent doing changes on a live environment by mistake. To enable it just add to the config.yaml:

helpers:
  environment: local

You can use local, dev, stg or prod and the you'll have an indicator in the cockpit site name and a border line in main header, e.g.:

Local

Local Environment

Prod

Prod Environment

Assets in modules menu

The modules menu includes core Collections, Singletons and Forms, the Helpers addon makes a menu entry for Assets:

Assets

Quick Actions

A simple UI element that is present in the modules navigation bar and can be configured (config.yaml) to display a list of quick actions. Actions can be aggregated in groups, and can be a link to whatever you need, for example:

helpers:
  quickactions:
    - group: Create
      actions:
        - label: Post
          path: /collections/entry/post
        - label: Page
          path: /collections/entry/page
        - label: Categories
          path: /collections/entry/category
    - group: Accounts
      actions:
        - label: New
          path: /accounts/create

Quick Action

Collection Entries extra sidebar actions

The addon extends the sidebar when viewing a collection entry with 3 handy extra actions:

  • Add new entry (create a new entry without leaving the page)
  • Duplicate (clone) the existing entry (without leaving the page)
  • Delete the existing entry

Cockpit collection entry extra actions

Content Preview url override

By default the Cockpit preview url is tied to the collection structure, and therefore is not possible to have different urls (e.g. for local environment or dev/stage environments). The Helpers addon provides a mechanism to override the url in the config.yaml file. For example, if we have a configured url in the collection like below:

Preview Url

And in the config.yaml we have an entry like:

helpers:
  preview:
    url: https://localhost:3003

Cockpit will use https://localhost:3003/preview/page as preview url.

Collection Select Field

Cockpit provides the Collection Link field to easily reference collection entries, however for some scenarios (e.g. we have a small and fixed number of items) a select element can be more useful.

The Collection Select field accepts the same parameters in the field definition as the Collection Link field, e.g.:

{
  "link": "page",
  "display": "title",
  "limit": 20
}

The field requires an ACL (for non admin users) to be set in the config, e.g:

groups:
  editor:
    helpers:
      collectionSelect: true

Singleton Select Field

Cockpit doesn't provide a mechanism to link to singletons, however for some scenarios (e.g. define global data like blocks) it can be useful.

The Singleton Select field accepts the below parameters:

{
  "group": "Blocks",
  "limit": 20
}

The field requires an ACL (for non admin users) to be set in the config, e.g:

groups:
  editor:
    helpers:
      singletonSelect: true

Max Revisions

Cockpit by default creates revisions for collections and singletons without a limit, so we can end with thousands of revisions for a collection/singleton, mostly when performing batch updates or tests.

The helpers addon provides a mechanism to set a limit per collection/singleton or to all collections or singletons:

  • Set max revisions to 10 for all collections and singletons
helpers:
  maxRevisions:
    collections: 10
    singletons: 10
  • Set max revisions to 10 to all collections/singletons and 15 to page collection.
helpers:
  maxRevisions:
    collections: 10
    singletons: 10
    page: 15

Unique Fields

Cockpit by default permits to create entries with same values, that can be an issue for example when we want to have a unique title.

The addon provides via configuration the possibility to define per collection the fields that should be unique, e.g.:

helpers:
  uniqueFields:
    page:
      - title
    city:
      - title
      - name

PLEASE NOTE THAT BY ACTIVATING ABOVE WILL REMOVE THE COCKPIT DUPLICATE FUNCTIONALITY

Locks Removal

When editing contents cockpit provides a lock editing feature, however that seems to not be expired, and to avoid ending with contents locked for a long time the Helpers provide a cli command to remove the locks (e.g. to be used in a cron command).

# Remove all locks
$ php cp reset-expiredlocks

# Remove locks older than 6h (21600s)
$ php cp reset-expiredlocks --time 21600

Cockpit search on collections

Cockpit provides a basic global search that can be used to search on pre-defined set of elements like collection types or user accounts. The helpers addons extends that functionality to work also on collection entries, making possible to search directly on any collection type entries.

To active that functionality add to your config.yaml the collections and title field name you want to perform search, e.g.:

helpers:
  cockpitSearch:
    limit: 10
    collections:
      page: title
      post: title

On the above example when hitting the global search cockpit will return results from collections page and post (on the field title):

Search

Basic migrations CLI command

On the event you have a running website and you need to change some field structures, it can be helpfull to have a mechanism to run the changes against the updated contents. The addon provides a very simple CLI command that works as a convention/wrapper for your migration script, all the logic behind the migration is still required to be handled by you.

Put your script on your addon inside a migrations folder, e.g.: <addon_name>/migrations/20190710-update-posts.php containing a function name migration_20190710_update_posts, contents can be like below:

<?php
// Update post contents field date type.
function migration_20190710_update_posts($app) {
  $collection = $app->module('collections')->collection('posts');
  $entries = $app->storage->find("collections/{$collection['_id']}")->toArray();
  foreach ($entries as $entry) {
    // Perform your changes.
    $entry['field_xpto'] = [...];
    // And save entry.
    $app->module('collections')->save('posts', $entry, ['revision' => TRUE]);
  }
}

and just run the command:

$ php cp --addon <addon_name> --name 20190710-update-posts

Installation

  1. Confirm that you have Cockpit CMS (Next branch) installed and working.
  2. Download zip and extract to 'your-cockpit-docroot/addons' (e.g. cockpitcms/addons/Helpers) (Ensure that the addon folder is named Helpers)

Copyright and license

Copyright 2018 pauloamgomes under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].