| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- import APIRepository from '../classes/APIRepository'
- import { appApi } from 'src/boot/axios'
- import { TreeNode, TreeNodeList } from 'src/models/TreeNode.js'
- const APIAdresses = {
- base: '/forrest/tree',
- bulkIndex: '/forrest/tree/bulk',
- tags: '/forrest/tags',
- grid: (grid) => '/forrest/tree/' + grid,
- getMultiType: (types) => {
- let treeAddress = '/forrest/tree?'
- types.forEach(element => {
- treeAddress = treeAddress + `multi-type[]=${element}&`
- })
- return treeAddress
- },
- getGradesList: '/forrest/tree?type=test',
- getNodeById(nodeId) {
- return '/forrest/tree/' + nodeId
- },
- getNodeByType(nodeType) {
- return '/forrest/tree?type=' + nodeType
- },
- getNodeByTitle(nodeType) {
- return '/forrest/tree?title=' + nodeType
- },
- editNode(id) {
- return '/forrest/tree/' + id
- },
- getLessonList(lessonId) {
- return '/forrest/tree/' + lessonId
- }
- }
- export default class ForrestAPI extends APIRepository {
- constructor() {
- super('tree', appApi, '', '', APIAdresses)
- this.CacheList = {
- base: this.name + this.APIAdresses.base,
- bulkIndex: this.name + this.APIAdresses.bulkIndex,
- tags: this.name + this.APIAdresses.tags,
- grid: (grid) => this.name + this.APIAdresses.grid(grid),
- getMultiType: (grid) => this.name + this.APIAdresses.getMultiType(grid),
- getGradesList: this.name + this.APIAdresses.getGradesList,
- getNodeById: nodeId => this.name + this.APIAdresses.getNodeById(nodeId),
- getNodeByType: nodeType => this.name + this.APIAdresses.getNodeByType(nodeType),
- getNodeByTitle: nodeTitle => this.name + this.APIAdresses.getNodeByTitle(nodeTitle),
- editNode: id => this.name + this.APIAdresses.editNode(id),
- getLessonList: id => this.name + this.APIAdresses.getLessonList(id)
- }
- }
- index(data) {
- return this.sendRequest({
- apiMethod: 'get',
- api: this.api,
- request: this.APIAdresses.base,
- data: this.getNormalizedSendData({
- page: 1 // Number
- }, data),
- resolveCallback: (response) => {
- return {
- treeNodeList: new TreeNodeList(response.data.data),
- paginate: response.data.meta
- // {
- // current_page: 1,
- // from: 1,
- // last_page: 1,
- // path: '...',
- // per_page: 15,
- // to: 10,
- // total: 10
- // }
- }
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- base(data = {}) {
- return this.sendRequest({
- apiMethod: 'get',
- api: this.api,
- request: this.APIAdresses.base,
- cacheKey: this.CacheList.base,
- ...(data?.cache && { cache: data.cache }),
- resolveCallback: (response) => {
- return new TreeNode(response.data.data)
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- createNode(data = {}) {
- return this.sendRequest({
- apiMethod: 'post',
- api: this.api,
- request: this.APIAdresses.base,
- cacheKey: this.CacheList.base,
- data: data.data,
- ...(data?.cache && { cache: data.cache }),
- resolveCallback: (response) => {
- return new TreeNode(response.data.data)
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- getNodeBy(value, data) {
- const methodName = 'getNodeBy' + value
- let param = data.data.nodeType
- if (value === 'Id') {
- param = data.data.id
- }
- return this.sendRequest({
- apiMethod: 'get',
- api: this.api,
- request: this.APIAdresses[methodName](param),
- cacheKey: this.CacheList[methodName](param),
- ...(data?.cache && { cache: data.cache }),
- resolveCallback: (response) => {
- return new TreeNode(response.data.data)
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- getNodeById(data) {
- return this.getNodeBy('Id', data)
- }
- getNodeByType(data) {
- return this.getNodeBy('Type', data)
- }
- getNodeByTitle(data) {
- return this.getNodeBy('Title', data)
- }
- editNode(nodeId, data) {
- return this.sendRequest({
- apiMethod: 'put',
- api: this.api,
- request: this.APIAdresses.editNode(nodeId),
- cacheKey: this.CacheList.editNode(nodeId),
- ...(data?.cache && { cache: data.cache }),
- data: data.data,
- resolveCallback: (response) => {
- return new TreeNode(response.data.data)
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- getGradesList(data = {}) {
- return this.sendRequest({
- apiMethod: 'get',
- api: this.api,
- request: this.APIAdresses.getGradesList,
- cacheKey: this.CacheList.getGradesList,
- ...(data?.cache && { cache: data.cache }),
- resolveCallback: (response) => {
- return response.data.data.children
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- getLessonList(data = {}) {
- return this.sendRequest({
- apiMethod: 'get',
- api: this.api,
- request: this.APIAdresses.getLessonList(data.data.id),
- cacheKey: this.CacheList.getLessonList(data.data.id),
- ...(data?.cache && { cache: data.cache }),
- resolveCallback: (response) => {
- return response.data.data.children
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- getTags(data = {}, cache) {
- return this.sendRequest({
- apiMethod: 'get',
- api: this.api,
- request: this.APIAdresses.getMultiType(data),
- cacheKey: this.CacheList.getMultiType(data),
- ...(cache && { cache }),
- resolveCallback: (response) => {
- return response.data.data
- // return fillFakeData()
- },
- rejectCallback: (error) => {
- return error
- // return fillFakeData()
- }
- })
- }
- }
- // function fillFakeData() {
- // const treeNodes = [
- // {
- // children: [
- // {
- // id: '6281fbeb2f1bafe99f050336',
- // title: 'پایه دوازدهم',
- // parent: {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // },
- // ancestors: [
- // {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // }
- // ],
- // order: 1,
- // type: null,
- // number_of_children: 20,
- // updated_at: '2022-06-06 12:54:01',
- // created_at: '2022-05-16 11:53:23'
- // },
- // {
- // id: '628204312f1bafe99f050346',
- // title: 'پایه یازدهم',
- // parent: {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // },
- // ancestors: [
- // {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // }
- // ],
- // order: '1',
- // type: null,
- // number_of_children: 22,
- // updated_at: '2022-06-06 12:55:19',
- // created_at: '2022-05-16 12:28:41'
- // },
- // {
- // id: '62947d2624d62d858d09a4d2',
- // title: 'پایه دهم',
- // parent: {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // },
- // ancestors: [
- // {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // }
- // ],
- // order: 1,
- // type: null,
- // number_of_children: 19,
- // updated_at: '2022-06-06 12:58:16',
- // created_at: '2022-05-30 12:45:34'
- // },
- // {
- // id: '628204c52f1bafe99f05034a',
- // title: 'پایه نهم',
- // parent: {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // },
- // ancestors: [
- // {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // }
- // ],
- // order: '3',
- // type: null,
- // number_of_children: 8,
- // updated_at: '2022-06-06 12:56:52',
- // created_at: '2022-05-16 12:31:09'
- // },
- // {
- // id: '6284c10647a54520840442a2',
- // title: 'پایه هشتم',
- // parent: {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // },
- // ancestors: [
- // {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // }
- // ],
- // order: '4',
- // type: null,
- // number_of_children: 7,
- // updated_at: '2022-06-06 12:56:59',
- // created_at: '2022-05-18 14:18:54'
- // },
- // {
- // id: '629dba608c4d7e26720cece3',
- // title: 'پایه هفتم',
- // parent: {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // },
- // ancestors: [
- // {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // }
- // ],
- // order: '4',
- // type: null,
- // number_of_children: 7,
- // updated_at: '2022-06-06 12:57:12',
- // created_at: '2022-06-06 12:57:12'
- // },
- // {
- // id: '629dba888c4d7e26720cece5',
- // title: 'پایه ششم',
- // parent: {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // },
- // ancestors: [
- // {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // }
- // ],
- // order: '7',
- // type: null,
- // number_of_children: 6,
- // updated_at: '2022-06-06 12:57:52',
- // created_at: '2022-06-06 12:57:52'
- // },
- // {
- // id: '629dc3b58c4d7e26720ced28',
- // title: 'پایه پنجم',
- // parent: {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // },
- // ancestors: [
- // {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // }
- // ],
- // order: '8',
- // type: null,
- // number_of_children: 5,
- // updated_at: '2022-06-06 13:37:01',
- // created_at: '2022-06-06 13:37:01'
- // },
- // {
- // id: '62f8eb444dcdcce15d084e62',
- // title: 'پایه چهارم',
- // parent: {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // },
- // ancestors: [
- // {
- // id: '6281fb9e2f1bafe99f050334',
- // title: 'درخت دانش'
- // }
- // ],
- // order: '9',
- // type: null,
- // number_of_children: 0,
- // updated_at: '2022-08-23 17:26:06',
- // created_at: '2022-08-14 17:02:04'
- // }
- // ]
- // },
- // {
- // children: [
- // {
- // id: '63ff427566344faf860f0f9f',
- // title: 'دبیر 1',
- // parent: {
- // id: '63f37272c590054efc012d12',
- // title: 'دبیر'
- // },
- // ancestors: [
- // {
- // id: '63f37272c590054efc012d12',
- // title: 'دبیر'
- // }
- // ],
- // order: '0',
- // type: null,
- // number_of_children: 0,
- // updated_at: '2023-03-01 15:49:18',
- // created_at: '2023-03-01 15:47:57'
- // },
- // {
- // id: '63ff427c66344faf860f0fa0',
- // title: 'دبیر 2',
- // parent: {
- // id: '63f37272c590054efc012d12',
- // title: 'دبیر'
- // },
- // ancestors: [
- // {
- // id: '63f37272c590054efc012d12',
- // title: 'دبیر'
- // }
- // ],
- // order: '2',
- // type: null,
- // number_of_children: 1,
- // updated_at: '2023-03-01 15:49:18',
- // created_at: '2023-03-01 15:48:04'
- // },
- // {
- // id: '63ff429866344faf860f0fa2',
- // title: 'دبیر 3',
- // parent: {
- // id: '63f37272c590054efc012d12',
- // title: 'دبیر'
- // },
- // ancestors: [
- // {
- // id: '63f37272c590054efc012d12',
- // title: 'دبیر'
- // }
- // ],
- // order: '3',
- // type: null,
- // number_of_children: 0,
- // updated_at: '2023-03-01 15:49:18',
- // created_at: '2023-03-01 15:48:32'
- // },
- // {
- // id: '63ff42b466344faf860f0fa3',
- // title: 'دبیر 4',
- // parent: {
- // id: '63f37272c590054efc012d12',
- // title: 'دبیر'
- // },
- // ancestors: [
- // {
- // id: '63f37272c590054efc012d12',
- // title: 'دبیر'
- // }
- // ],
- // order: '4',
- // type: null,
- // number_of_children: 0,
- // updated_at: '2023-03-01 15:49:18',
- // created_at: '2023-03-01 15:49:00'
- // }
- // ]
- // }
- // ]
- // return treeNodes
- // }
|