# we-bases

> ya Ali

Latest version **0.2.0** (published 2020-07-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install we-bases
pnpm add we-bases
yarn add we-bases
bun add we-bases
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2020-07-09 |
| First published | 2020-07-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 80 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | saeid_01 |
| Maintainers | saeid_01 |

## Links

- npm: https://www.npmjs.com/package/we-bases
- Repository: https://git.willaspace.com/WE-Packages/base
- npm.io page: https://npm.io/package/we-bases

## Recent versions

- 0.2.0 (latest) — 2020-07-09

## README

# Package we-bases
What does this package do?
1. set Global method mixin in project
    - `$_asset(path)`
    - `$_name(path, text)`
    - `$_color(slug)`
    - `$_dialog(properties)`
    - `$_helper(slug)`
    - `$_openModal(name, data = {}, $can = null)`
    - `$_closeModal(slug)`
2. set Global data mixin in project
    - `modal = false`
    - `modal_data = {}`
3. set Global components
    - use `<we-base />` for dialog and helper
4. set Global directive
    - example `v-can:client-edit.disable="postObject"`
    - example `v-soon.disable="client-list"`
5. has `{urlGenerator}` 
6. Load Category names and store in local storage

- this package a special package for willaengine project
## Prerequisites

- [x] use package we-axios. 

##install

```
npm install we-bases
```

##Usage

use in main:
```javascript
import Base from 'we-bases'
Vue.use(Base, options);
```

defult Options: 

```javascript
const options = {
    basic_roues: {
         login: "/ms-login",
         main: "/main/home",
         user: "/user/list",
         originHostName: 'www.willaengine.ir',
         api: 'https://www.willaengine.ir'
    },
    prefix: 'v1'
};
```
##Mixin

###Assets
use for image or file static from https://www.willaengine.ir 

if `Vue.config.devtools == true`  => subpath equal `'/'` 

if `Vue.config.devtools == true`  => subpath equal `'https://www.willaengine.ir/'`

```javascript
$_asset(path);
```

###Nomenclature
For names that are going to change according to the customer's needs

get list name from server and save in local storage


```javascript
$_name(path, text);
//example $_name('common.task.name', 'ثبت $_name')
```

define default name in install package and projects:

```javascript
const Task = {
    my_task: {name: ' وظایف من ', name_en: ' My Tasks '},
    my_request: {name: ' درخواست های من ', name_en: ' My Requests '},
    title: {
        add: {name: 'تعریف وظیفه ', name_en: ' Define a Task '},
        add_category: {name: 'افزودن نوع وظیفه', name_en: ' Add a Task Type '},
        list_category: {name: ' مدیریت انواع وظیفه ', name_en: ' Manage the Task types '},
        add_status: {name: ' افزودن وضعیت وظیفه ', name_en: '  Add a Task Status  '},
        list_status: {name: 'مدیریت وضعیت وظیفه ', name_en: '  Manage the Task Status  '},
        detail: {name: 'جزیئات وظیفه ', name_en: '  Task Details  '},
        change_status: {name: 'تغییر وضعیت وظیفه ', name_en: 'Change Task Status'},
    },
    name: 'وظیفه',
    name_en: 'Task',
    names: 'وظایف',
    name_ens: 'Tasks',
    begin_date: {name: 'تاریخ شروع وظیفه', name_en: 'Task Begin Date'},
    end_date: {name: ' تاریخ اتمام وظیفه ', name_en: 'Task End Date'},
    category: {name: 'نوع وظیفه', name_en: 'Task Type'},
    status: {name: 'وضعیت وظیفه', name_en: 'Task Status'},
    responsibility: {name: 'مسئول وظیفه', name_en: 'Task Responsibility'},
};
Vue.prototype.$defaultNames['task'] = Task;
```

###Colors
All WillaEngine project packages that have a special color should be added colors to `Vue.prototype.$specialColors` Variable

use in component
```javascript
$_color(slug);
//example $_color('task')
```

add in package in install OR add in Projects
```javascript
const taskColors = {
task: 'red',
task_status: 'brown',
task_category: 'yellow'
}
Object.assign(Vue.prototype.$specialColors, taskColors);
```

###Dialog

```javascript
$_dialog(properties)
//example $_dialog({success: () => {removeCategory(item)}})
```

default properties variable:

```javascript
const properties = {
    type: "delete",
    success: function() {
        return "";
    },
    close: function() {
        return "";
    },
    message:
        "آیا از حذف آیتم مطمئن هستید؟ امکان بازگشت وجود نخواهد داشت.",
    title: " تایید حذف ",
    titleEn: " Remove Confirmation ",
    color: "red",
    cancelButtonText: "انصراف",
    confirmButtonText: "حذف",
    cancelButtonColor: "cyan",
    confirmButtonColor: "red"
}
```

###Helper
Passing the slug will prompt you to request this api `v1/help/${slug}`  and get response from server for this slug
```javascript
$_helper(slug)
//example $_helper('index-category')
```

###Modal

in all components you access to variable data => `modal` and `modal_data`

`modal` is boolean

`modal_data` is object passing from `$_openmodal`

```javascript
$_openModal(name, data = {}, $can = null)
$_closeModal()
//example $_openModal(name, data = {}, $can = null)
```
`name` is component name except modal 

example://  component name is `modal_task_list` => `name` passing in `$_openModal('name')` is `task_list`

`data` access in modal component `modal_data` variable

`$can` is object policy `$can.model` `$can.method`

```javascript
$can = {model: 'Client', method: 'index', data}
//data is passing data to directive can
//if data not passing, use data passing to $_openModal()

// OR Use 
$can = "Client::index"
// In this case, the data becomes the data used in the $_openModal()
````
 
##Directive

###Policy
must be define class policy in packages and merge with `Vue.prototype.$policies`

in directory `policy` file `TaskStatusPolicy.js`
```javascript
export default class TaskStatusPolicy {
    //permissions => Object.values(rootPermissions[module])
    //module => Vue.prototype.$module.current
    //rootPermissions => Vue.prototype.$permission

    index({module, rootPermissions, permissions}) {
        return permissions.includes('manage-task-status');
    }
    
    create({permissions}) {
        return permissions.includes('manage-task-status');
    }
    
    update({permissions}, object) {
        return permissions.includes('manage-task-status') || object.owner;
    }
    
    delete({permissions}, object) {
        return permissions.includes('manage-task-status') || object.owner;
    }
    
}
```

in directory `policy` file `index`
```javascript
import TaskStatus from './TaskStatusPolicy'
import Task from './TaskPolicy'
Vue.prototype.$policies['TaskStatus'] = TaskStatus;
Vue.prototype.$policies['Task'] = Task;
```

```vue
//disable
<div v-can:client-show.disable="client" >{{client.name}}</div>

//hidden
<div v-can:client-show="client" >{{client.name}}</div>
```
`client-show` => `client` is model name and `show` is method name split with `-`

###CommingSoon
must be define array in packages and merge with `Vue.prototype.$soon`

```vue
//hidden
<div v-soon="'client'" ><component /></div>

//disable
<div v-soon.disable="'client'" ><btn /></div>
```


## Usage URL Generator

file `./url.js`
```javascript
import {urlGenerator} from 'we-bases'
//use prefix in import Base from 'we-bases'
//Vue.use(Base, {prefix: 'v1'});

const urls = {
	//Cities && Districts
	indexCities: "cities",
	showCity: "city/:city",
}
export default url = urlGenerator(urls);
```

use in other file
```javascript
import urls from './url'
import {axios} from 'we-axios'
$axios.get(urls('showCity', {city: 1}))
```

---
_Source: https://npm.io/package/we-bases · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
