0.6.0 • Published 8 months ago

strapi-plugin-models v0.6.0

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

⚠️ This plugin is not finished yet! ⚠️

Strapi plugin models {WIP}

A plugin for Strapi Headless CMS that provides an independent environment for managing simple models, fields and elements from external source inside Strapi UI.

API supports viewing, creating, editing and deleting models, model fields and model elements.

Installation

First, you should install Strapi itself (following documentation for v3.0).

Then install this plugin from Strapi root folder as follows.

npm i strapi-plugin-models@latest

OR

yarn add strapi-plugin-models@latest

OR

If you have a source code, just copy it to the ./plugins/models folder

After successful installation you've to build a fresh package that includes plugin UI. To achieve that simply use:

yarn build
yarn develop

or just run Strapi in the development mode with --watch-admin option:

yarn develop --watch-admin

The Models plugin should appear in the Plugins section of Strapi sidebar after you run app again.

⚠️ ENV variables

Models plugin uses external API url for all requests. The correct URL should be placed in app environment (for example, ./.env) in a variable PLUGIN_MODELS_URL.

⚠️ NPM conflict resolution

This plugin uses newer version of react-query and thus — match-sorter. To resolve this issue add this lines to your Strapi package.json. (up to date for strapi v.3.6.7)

  "resolutions": {
    "match-sorter": "^4.0.2"
  },

⚠️ API Permissions

Do not forget to add permissions to plugin controls. To do that, go to: Settings → Users & Permissions plugin → public → Permissions → Models and check "Select all".

Public API routes

host root is pulled from the node environment variable PLUGIN_MODELS_URL.

  • GET <host>/admin/models - get models list
  • GET <host>/admin/models/:id - get one model
  • POST <host>/admin/models - create model
  • PUT <host>/admin/models/:id - update model
  • DELETE <host>/admin/models/:id - delete model
  • GET <host>/admin/models/:id/fields - get fields list
  • GET <host>/admin/models/:id/fields/:fieldId - get one model field
  • POST <host>/admin/models/:id/fields - create model field
  • PUT <host>/admin/models/:id/fields/:fieldId - update model field
  • DELETE <host>/admin/models/:id/fields/:fieldId - delete model field
  • GET <host>/admin/models/:id/elements - get elements list
  • GET <host>/admin/models/:id/elements/:elementId - get one model element
  • POST <host>/admin/models/:id/elements - create model element
  • PUT <host>/admin/models/:id/elements/:elementId - update model element
  • DELETE <host>/admin/models/:id/elements/:elementId - delete model element

Public API items models

Model

{
  "id": 1,
  "name": "Model",
  "code": "model"
}

Model field

{
  "id": 1,
  "name": "Field",
  "code": "field",
  "type": "string",
  "referenceCode": "reference",
  "modelCode": "model",
  "required": false,
  "multiple": false,
  "filterable": false
}

Model element

{
  "id": 1,
  "fieldValues": [
    {
      "modelFieldId": 1,
      "value": "string"
    },
    {
      "modelFieldId": 2,
      "value": ["string"]
    }
  ]
}

How to add new functionality

All relative paths are specified for the plugin root

Create new UI components

  • New functional UI is created in ./admin/src/containers for complex logic blocks and ./admin/src/components for simple blocks.
  • New routes are added in ./admin/src/containers/App/index.js like so:
import NewContainer from '../NewContainer';

const App = () => {
  return (
    <Providers...>
      <Container>
        <Switch>
          <Route
              path={`/plugins/${pluginId}/your-desired-path`}
              component={NewContainer}
              exact
          />
          ...

Create new API methods

  • External methods are created in ./controllers/models like so:
module.exports = {
    ...,
    async newMethod(ctx) {
        // ...your logic
        ctx.send(result);
    }
}
  • Internal routes are created in ./config/routes.json like so:
{
  "routes": [
    ...,
    {
      "method": "GET",
      "path": "/path-relative-to-plugin",
      "handler": "models.newMethod", // <-- method from ./controllers
      "config": {}
    }
  ]
}

Add new assets

  • New assets are added in ./public/assets;
  • Can be used as src="public/assets/asset-name.ext"
0.5.58

10 months ago

0.5.59

10 months ago

0.5.61

9 months ago

0.5.60

9 months ago

0.6.0

8 months ago

0.5.54

1 year ago

0.5.55

1 year ago

0.5.56

1 year ago

0.5.57

1 year ago

0.5.52

1 year ago

0.5.53

1 year ago

0.5.50

1 year ago

0.5.51

1 year ago

0.5.43

2 years ago

0.5.44

2 years ago

0.5.41

2 years ago

0.5.42

2 years ago

0.5.40

2 years ago

0.5.49

1 year ago

0.5.47

2 years ago

0.5.48

1 year ago

0.5.45

2 years ago

0.5.46

2 years ago

0.5.32

2 years ago

0.5.33

2 years ago

0.5.30

2 years ago

0.5.31

2 years ago

0.5.38

2 years ago

0.5.39

2 years ago

0.5.37

2 years ago

0.5.34

2 years ago

0.5.35

2 years ago

0.5.29

2 years ago

0.5.27

2 years ago

0.5.28

2 years ago

0.5.26

2 years ago

0.5.25

3 years ago

0.5.24

3 years ago

0.5.23

3 years ago

0.5.18

3 years ago

0.5.16

3 years ago

0.5.14

3 years ago

0.5.15

3 years ago

0.5.13

3 years ago

0.5.21

3 years ago

0.5.20

3 years ago

0.5.10

3 years ago

0.5.11

3 years ago

0.5.12

3 years ago

0.5.8

3 years ago

0.5.7

3 years ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.6

3 years ago

0.5.0

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.0

3 years ago