0.1.1-rc.13 • Published 4 years ago

@apok/admin v0.1.1-rc.13

Weekly downloads
108
License
-
Repository
-
Last release
4 years ago

Apok-admin

The VueJS plugin for REST and GraphQL web clients projects scaffolding

When a web application is being develop there are common concepts that come across very often and coding them over and over can be a somewhat painful experience for some developers. During this process of writing repetitive code, human mistakes become a more relevant factor, especially for those lacking the expertise. This is why scaffolding is an important resource in terms of efficiency; it allows the developer to focus in the implementation details of the app while letting the scaffolding software to generate the base code.

And yes, scaffolding might feel like a bad practice in particular for new developers, however, a scaffold does not mean you wont do any coding, it means you can put the effort and creativity into really solving a problem, implementing a new feature from scratch without the worry of messing fundamental code.

Here is where Apok-admin excels at: generating base code for your Vue-js web application. You can create fully working Vuex and admin modules with semantically friendly console commands, start your developing experience ASAP just as the installation ends with all dependencies already added from the beginning, get your api (or a mocked one, great for testing) working in minutes just by setting an endpoint, work with ready-to-develop Vue components using the most popular CSS frameworks available, and many more!

There's a lot of reasons of why you should use Apok-admin, and just to name a few, here's a list of what Apok-admin allow you to:

  • Develop what makes your app unique; keeping the base stuff to Apok-admin.
  • Makes the developing faster; by making fully working modules a console command away.
  • Fully customizable code; there's no point on generating a scaffold that you can't customize to suite your needs.
  • Work with ready-to-develop components styled with the most pupular CSS frameworks; made with the intention to accomplished advanced functionality while being easy to use.
  • Create language friendly apps; with i18n make sure your app is international.
  • Choose which icon pack you want and make you app more descriptive; FontAwesome icons, MDI or Unicons for Vue!

Apok-admin is as great as it looks and it's easy to install too! go to the next part and keep reading to get started!

Table of Contents

Installation

As a vue-cli plugin you need to install vue-cli system using npm install

  • npm install -g @vue/cli

then create a new vue project with vue create -d. The -d flag will install the default vue template (ESLint + Babel). All dependencies needed are installed with Apok-admin itself.

  • vue create -d <myProjectName>

Now you need to install Apok-admin via vue add vue-cli console command

  • vue add @apok/apok-admin

During apok-admin's installation you'll be prompted with a few initial configuration questions in this order:

  • CSS Framework, a single selection option where you may choose between bootstrap or bulma as your main components CSS framework
  • What icons do you want to use?, a multiple selection option where you may choose the desired icon pack from those available:
  • Will you use a REST client? (y/n), a closed question for the REST plugin installation
  • Will you use GraphQL (y/n), a closed question for the GraphQL plugin installation

Finally, you have to install all dependencies added to your project's package.json

  • npm install

After everything is installed there are a few things to be configured before start developing:

  • Set the REST and/or GraphQL endpoints in src/config/admin.js file:

       //If you chose using a REST client
       Vue.use(NetworkRestPlugin, {
         baseURL: 'your api URL goes here',
         sessionCookie: constants.SESSION_COOKIE
       });
        
       //If you chose using GraphQL
       Vue.use(NetworkGraphQLPlugin, {
         baseURL: 'your api URL goes here',
         sessionCookie: constants.SESSION_COOKIE
       });
  • Setting a new menu option object in the src/config/menu.js file default array. This way you can start using the top-left menu of the layout to navigate to your views:

    ```javascript
      // menu.js
      export default [
        //New menu entry
        {
          title: 'Your menu entry title',
          children: [
            {
              label: 'Your menu item lebel',
              to: { name: 'Named Route' },
              icon: {icon: 'icon of choice'}
            },
          ]
        },
      ]
    ```
  • Create a new admin or vuex module to start consuming your api of choice, running the create script added in project's package.json, for a better description you can go here

At this point you are able to run the vue-cli dev server using npm run serve and ready to start developing!

Folder structure

After installation has been done, your project's source folder should look like this:

├── src
|   ├── assets
|   ├── components
|   ├── config
|   ├── features
|   ├── i18n
|   ├── store
|   ├── tests
|   ├── utils
|   ├── views
|   ├── App.vue
|   ├── main.js
|   ├── registerServiceWorker.js
|   └── router.js
  • Assets

    The assets folder contains the files associated with the CSS style processed by Sass and applied to the project globally. Check Sass documentation for more info

    FileDescription
    _variables.scssCustom styles file
    main.scssmain Sass file
  • Components

    In here should go any custom components created by you. Let's say you have a simple button component:

    //myButtonComponent.vue
    <template>
        <button v-on:click="doSomething"> Click Me! </button>
    </template>
    <script>
        export default {
            name: 'MyButtonComponent',
            methods: {
                doSomething: () => {
                    alert('You clicked me and I did something!')    
                }        
            }
        }
    </script>

    When you need to use it, add it as a property in the components install in the main.js file. Such as:

    //main.js
    import BootstrapAdminComponents from "@apok/admin-components-bootstrap";
    import myButtonComponent from '@/components/myButtonComponent.vue'
    
    Vue.use(BootstrapAdminComponents, {
        'ButtonRenderer': myButtonComponent
    })
  • Config

    Various configuration files. Feel free to modify them as you need

    FileDescription
    admin.jsREST and GraphQL config file
    constants.jsGlobal constants for project
    filters.jsCustom Vue filters
    fontawesome.jsFontawesome icons configuration
    i18n.jsTranslation file
    index.jsEntire config module export
    menu.jsMenu sample
  • admin.js

    This file contains the installation of the REST and GraphQL instance. In here you should set the endpoints you are willing to use in your app. You can even use a mocked endpoint for development using API mocking tools like mirage.js or MockServer
    • REST configuration

      By default, apok-admin uses axios for http requests. This can be set by the user in case axios is not the option you want or you need a custom axios implementation:

        // admin.js
      
        //Custom axios implementation
        const myHttpClient = axios.create(options) //Or any http client
      
        Vue.use(NetworkRestPlugin, {
         baseURL: 'your api URL goes here',
         sessionCookie: constants.SESSION_COOKIE,
         httpClient: myHttpClient,
        });
  • constants.js

    As the name may suggest, this is where your global constants might be set. The point is to use recurrent values in shape of constants that are also available globally through the Vue instance. Once a value is set, it can be accessed to using the Vue instance object, like:

      // Any file
    
      import Vue from 'vue';
      Vue.constants.YOUR_CONSTANT_NAME;
  • filters.js

    Here you should find useful filters for string and date formatting purposes, and array manipulation. Also, there's a custom directive for svg images inserting. You can set as many filters and directives as you want.

  • fontawesome.js

    Contains the font-awesome-icon vue component installation.

  • i18n.js

    This is the vuex-i18n plugin installation file. You can add your own translations as explained in their official documentation

  • menu.js

    This file is a simple array of objects export used in the main menu formatting of the MainLayout.vue component. Here should go any item you wish to add following the syntax of the example below:

      //menu.js
      export default [
        {
          title: 'General',                   //Menu section name
          children: [                         //Child routes
            {
              label: 'Dashboard',             //Menu item name
              to: { name: 'Dashboard' },      //Named rote
              icon: {icon: 'tachometer-alt'}  //Icon
            },
          ]
        },
      ]
  • Features

    All modules created with the plugin's CLI commands goes here. Every new module shall have its own folder with the necessary files for it to work. Check Console Commands for more info. There are two types of modules: Admin and Vuex modules, the last being an option inside of the first one.

    Important note: "MyAdminModule" and "MyVuexModule" are example names used for this part. Your modules should always be named as you want and in a more descriptive way in terms of functionality. However, the same logic described in this part applies to your module's files!

    • Admin modules

      This module comes with 3 template views for CRUD operations, for instance, you can get request data from your api and render it the List component, which also allows you to delete a registry, switch to the edit view to make changes or even create a new one. In case you need a more specific implementation on your CRUD views, feel free to modify the generated template to suit your needs. All components are named with the module's name and then suffixed with List for the listing component and Edit for the editing and new registry component. For example, if you module is called MyAdminModule, the components will be named as follows:

      ComponentDescription
      MyAdminModule.vueBase layout for List and Edit components
      MyAdminModuleList.vueList component. By default, it renders a table with data coming from a get request
      MyAdminModuleEdit.vueEdit and New registry component. Allows to change or create data via post or put requests respectively, using fields defined on form.js file

      Added to this, there are two more files corresponding a admin module:

      FileDescription
      routes.jsLocal routes file. This file is imported in the main router, so any route defined here will be available as a child in the main router instance
      form.jsThis file contains an export of an array of objects. It allows to format a form for the edit and new registry components. Object structure can be found here

      Finally if module creation command is flagged with --withTests, a __tests__ directory will be created storing the following Jest test files:

      FileDescription
      MyAdminModule.actions.spec.jsVuex actions test file
      MyAdminModule.mutations.spec.jsVuex mutations and states test file
      MyAdminModule.components.spec.jsViews components test file
    • Vuex modules

      As described in its official docs, Vuex is about state management. Apok-admin's Vuex module creation is no different; by using the corresponding command and options you can create an state management module that suits your needs. Basically, the command will create a vuex store with two variations depending on the options used: if --actions is used, apok-admin will generate the specified actions and mutations in a actions.js and mutations.js respectively. if --crud is used, then the plugin will import the storeGenerator function from the main store which allows the use of default CRUD implementation already in apok-admin.

      The module generated will be named as specified in the console command and will generate the following files:

      FileDescription
      actions.jsVuex actions file. In here will be created template actions for the specified ones in --actions's params
      mutations.jsVuex mutations file. Similar to the actions, in here will be created template mutations based on the actions names
      index.jsVuex module export
      types.jsVuex mutations constant types. This file will be generated only if --actions is used
  • i18n

    This is your translations folder. Inside should go every javascript file describing wich words i18n should translate to. For more information about this please refer to its official docs

  • Store

    Project's main Vuex store. This folder contains the main Vuex Store of your project's state management and works the same as specified in vuex's official docs. In Apok-admin's case there are three default modules that a web app might need: Authentication, Messages and UI for menu toggling. Also there's a folder named base where you can find a working CRUD store that you might adapt to suite your needs.

    • modules folder

      ModuleDescription
      authUser authentication module. Build with vuex actions and mutations that allows to retrieve a user's data and use it on your components
      messagesMessages module. Allows messages display on forms for UX purposes
      UIUser interface module. Has simple menu toggling functions for your UI controls
    • base folder

      The idea is to give a simple way to implement working CRUD and listing operations for your project. When a vuex module is created with apok-admin's console commands option --crud, the storeGenerator function will be imported from the baseStore.js file, which in turn, has baseActions.js and baseMutations.js imported. This allows an easy way to implement such functions on any vuex module you create.
      FileDescription
      baseActions.jsCRUD actions like getting a item list, deleting a item, saving a new item, updating an item, etc
      baseMutations.jsHolds the default mutations associated to corresponding CRUD and listing actions mentioned before
      baseStore.jsThis file has a store generator function that allows to create a store with the aforementioned actions and mutat
                    
  • Tests

    Contains views components and main Vuex store tests. All tests are coded between Jest and Vue Test Utils, the last one being the official unit testing utility library for Vue-js. In this folder should go all of your unit tests that aren't directly related to the modules in the features directory. There's a couple of test already coded for the main store and view components:
    FileDescription
    About.component.spec.jsAbout.vue component unit tests
    Dashboard.component.spec.jsDashboard.vue component unit tests
    Login.component.spec.jsLogin.vue component unit tests
    NotFoundPage.component.spec.jsNotFoundPage.vue component unit tests
    MainLayout.component.spec.jsMainLayout.vue component unit tests
    auth.store.spec.jsauth module unit tests
    messages.store.spec.jsmessages module unit tests
    ui.store.spec.jsui module unit tests
  • Utils

    In here goes any utility script you make. It is not required to be into this folder, but highly recommended for the sake of order

    FileDescription
    updatedPagedList.jsSample paged list update
  • Views

    Default components for view purposes. You can add as many custom components as you wish for your app's pages. It also contains some default components to start with:

    FileDescription
    About.vue"About Us" page example
    Dashboard.vueDashboard component
    Login.vueFunctional Login component
    NotFoundPage.vueSample error 404 view
    MainLayout.vueMain layout wrapper component

Usage

After installation, the plugin will auto run and start asking the configuration question for the scaffold, however if you need to run the plugin again you can use vue invoke command instead:

  • vue invoke @apok/apok-admin

Console commands

Apok-admin comes with built in commands for admin and vuex modules scaffolding that allows you to add specific functions to their projects. To use each command you must run the create script added to your package.json after apok-admin's installation, like this:

npm run create -- <command> --<option1> --<option2> --<optionN>
  • vuex:module command

    This command generates a folder named as the specified module name and generates the files for this vuex module to work: the store, actions, mutations and an index.js to bundle everything up.
    • Options

      OptionDescription
      --name <vuexModuleName>New name for the vuex module. Required
      --actions myAct1,myAct2...,myActNGenerates constant named actions and mutations. Constants are stored in a Types.js file. Requires argument
      --crudGenerates constant named actions and mutations as CRUD operations. Constants are stored in a ListTypes.js file. Optional
      --withTestsGenerates store test files. An .actions.spec.js for actions and a .mutations.spec.js for mutations and states. Optional
  • Vuex module folder structure

    Starting from myProject/src directory:
    ├── features
    |   ├── moduleName
    |       ├── tests           // if --withTests was used
    |           ├── moduleName.actions.spec.js  
    |           └── moduleName.mutations.spec.js  
    |       ├── store   
    |           ├── actions.js   
    |           ├── mutations.js   
    |           ├── index.js    // this vuex store exports
    |           └── types.js    // if --actions was used
    |       └── index.js        // use it to export your modules out of features wherever are needed   
  • admin:module command

    This command generates a folder named as the specified module name
    and creates default components to serve as views: main, edit and list. A routes.js es also generated to handle the new views and adds the possibility to generate a vuex module
    • Options

      OptionDescription
      --name <adminModuleName>New name for the admin module. Required
      --vuex <vuexModuleName>Generates an empty vuex module. Optional
      --vuexVar <vuexVarName>Name of the variable to bind to Data in edit/details views. Required
      --createVuexGenerates constant named actions and mutations as CRUD operations. Constants are stored in a ListTypes.js file. Optional
      --withTestsGenerates store test files. An .actions.spec.js for actions, a .mutations.spec.js for mutations and states, and a .components.spec.js for components. Optional
  • Admin module folder structure

    Starting from myProject/src directory:

    ├── features
    |   ├── moduleName
    |       ├── tests               // if --withTests is used
    |           ├── moduleName.actions.spec.js  
    |           ├── moduleName.mutations.spec.js  
    |           └── moduleName.components.spec.js  
    |       ├── store               // if --vuex or --createVuex is used
    |           ├── actions.js   
    |           ├── mutations.js   
    |           ├── index.js        // this vuex store exports
    |           └── types.js        // if --vuex was used, otherwise, refer to ListTypes.js in src/store
    |       ├── views           
    |           ├── moduleName.vue  
    |           ├── moduleNameEdit.vue   
    |           └── moduleNameList.vue    
    |       ├── moduleName.i18n     // Translations file      
    |       ├── forms.js     
    |       └── routes.js           // module routes

Components

One of Apok-admin's features are the default components. During the installation process you'll be prompted with various questions, including the CSS framework to use. Whichever CSS Framework you've chose, there shall be the same components coded with that respective CSS framework, thus treating in a more template oriented way. Of course this does not mean you can't use your own components, you can by just overwriting the renderer option in main.js. Learn more about it here.

  • Input components

    ComponentDescription
    InputFormCalendar.vueCalendar form component
    InputFormCheck.vueInput type check component
    InputFormFile.vueFile upload component
    InputFormMultiSelect.vueMultiple selection component
    InputFormRadio.vueInput type radio component
    InputFormSelect.vueSingle selection component
    InputFormText.vueText input component
    InputFormTextArea.vueText area input component
    InputFormTimePicker.vueAllow choosing hr and min as an input
  • Layout components

    ComponentDescription
    Layout.vueMain layout component
    LayoutNavBar.vueNavigation bar component
    LayoutMenu.vueSample menu component
    LayoutMenuItem.vueMenu item component for layout menu
    LayoutFooter.vueLayout's footer component
    Dashboard.vueDashboard component
  • Form components

    ComponentDescription
    AdminForm.vueMain form component
    AdminFormField.vueField component for main form
    IconButton.vueButton component
  • Miscellaneous components

    ComponentDescription
    Icon.vueIcon component
    AdminTable.vueSample table component
    Pagination.vuePagination component
    Messages.vueMessages and alerts component

Renderers

Apok-admin's components are registered into the Vue instance globally trough renderers, wich are just a generic name for a specific type of component. Thus, in case you want to make use of your own components, they should be assigned to a renderer in order to be part of the whole instance. We've mentioned before an example of how this works. Here is another one with Bulma components:

// in main.js

import BulmaAdminComponents from "@apok/admin-components-bulma";
import myCustomButton from '@/components/myCustomButton'
import myCustomTable from '@/components/myCustomTable'
import myCustomForm from '@/components/myCustomForm'

// In the admin components installation add your components as an object

Vue.use(BulmaAdminComponents, {
    'ButtonRenderer': myCustomButton,
    'TableRenderer': myCustomTable,
    'FormRenderer': myCustomForm,
})

Then on another component you can use the renderer as you would normally use a component, for instance:

<!-- Inside a Vue component template-->

<template>
    <div>
        <button-renderer/>
        <table-renderer/>
        <form-renderer/>
    </div>
</template>

Now you dont need to import every component you wish to use since they are already registered globally trough renderers!

This way you can add as much components as renderers are. Now a list of the available renderers:

InputLayoutFormMiscellaneous
FormInputTextRendererLayoutRendererFormRendererTableRenderer
FormInputPasswordRendererLayoutNavbarRendererFormRendererMessagesRenderer
FormInputNumberRendererLayoutFooterRendererPaginationRenderer
FormInputEmailRendererMenuRenderer
FormInputTelRendererMenuItemRenderer
FormInputColorRendererDashboardRenderer
FormInputSearchRenderer
FormInputUrlRenderer
FormInputFileRenderer
FormInputTextareaRenderer
FormInputSelectRenderer
FormInputRadioRenderer
FormInputCheckRenderer
FormInputCheckboxRenderer
FormInputCalendarRenderer
FormInputTimeRenderer
FormInputMultiSelectRenderer
0.1.1-rc.13

4 years ago

0.1.1-rc.12

4 years ago

0.1.1-rc.11

4 years ago

0.1.1-rc.10

4 years ago

0.1.1-rc.9

4 years ago

0.1.1-rc.8

4 years ago

0.1.1-rc.7

5 years ago

0.1.1-rc.6

5 years ago

0.1.1-rc.5

5 years ago

0.1.1-rc.4

5 years ago

0.1.1-rc.3

5 years ago

0.1.1-rc.2

5 years ago

0.1.1-rc.1

5 years ago

0.1.1-m

5 years ago

0.1.1-l

5 years ago

0.1.1-k

5 years ago

0.1.1-j

5 years ago

0.1.1-i

5 years ago

0.1.1-g

5 years ago

0.1.1-f

5 years ago

0.1.1-e

5 years ago

0.1.1-d

5 years ago

0.1.1-c

5 years ago

0.1.1-b

5 years ago

0.1.1-a

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago