From 9de4f752d2e58bf01f6ea55f8b3e179c13ca4647 Mon Sep 17 00:00:00 2001 From: comerc Date: Sat, 12 Oct 2019 17:02:09 +0300 Subject: [PATCH 1/8] Create tags.json --- src/data/tags.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/data/tags.json diff --git a/src/data/tags.json b/src/data/tags.json new file mode 100644 index 0000000..6638de7 --- /dev/null +++ b/src/data/tags.json @@ -0,0 +1,10 @@ +[ + { + "id": 1, + "name": "One" + }, + { + "id": 2, + "name": "Two" + } +] From 717371d760e3b8fcb0fc226d60dbf9725e5178e4 Mon Sep 17 00:00:00 2001 From: comerc Date: Sat, 12 Oct 2019 17:10:22 +0300 Subject: [PATCH 2/8] Added handlers for categories and tags --- src/globals/api-routes.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/globals/api-routes.js b/src/globals/api-routes.js index 1e1b039..03aecec 100644 --- a/src/globals/api-routes.js +++ b/src/globals/api-routes.js @@ -5,6 +5,7 @@ import { mediaList, createMedia } from './fake-media.js'; import users from '../data/users'; import taxonomies from '../data/taxonomies'; import categories from '../data/categories'; +import tags from '../data/tags'; import types from '../data/types'; import themes from '../data/themes'; @@ -176,12 +177,41 @@ export default [ // Categories { path: '/wp/v2/categories', - method: '*', + method: 'GET', handler () { - return categories; + return new window.Response(JSON.stringify(categories)); + }, + }, + { + path: '/wp/v2/categories', + method: 'POST', + handler({ payload: { name } }) { + return { + id: window.lodash.random(1, 100000000), + name, + }; }, }, + // Tags + { + path: '/wp/v2/tags', + method: 'GET', + handler() { + return new window.Response(JSON.stringify(tags)); + }, + }, + { + path: '/wp/v2/tags', + method: 'POST', + handler({ payload: { name } }) { + return { + id: window.lodash.random(1, 100000000), + name, + }; + }, + }, + // Users { path: '/wp/v2/users/', From a9a3e9a10d1194f23d4a5c1140160182f223890d Mon Sep 17 00:00:00 2001 From: comerc Date: Sat, 12 Oct 2019 17:14:14 +0300 Subject: [PATCH 3/8] Improved post data --- src/globals/fake-data.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/globals/fake-data.js b/src/globals/fake-data.js index 33e1233..79a2da7 100644 --- a/src/globals/fake-data.js +++ b/src/globals/fake-data.js @@ -54,13 +54,16 @@ export const pages = { theme_style: true, type: 'post', link: `${window.location.origin}/preview`, - categories: [ ], + categories: [1], + tags: [1, 2], featured_media: 0, permalink_template: `${window.location.origin}/preview`, preview_link: `${window.location.origin}/preview`, _links: { 'wp:action-assign-categories': [], 'wp:action-create-categories': [], + 'wp:action-create-tags': [], + 'wp:action-assign-tags': [], }, }, }; From d680df0ec2fba903c2b9e4667aec0ea15b2a8593 Mon Sep 17 00:00:00 2001 From: comerc Date: Sat, 12 Oct 2019 17:28:02 +0300 Subject: [PATCH 4/8] Removed space in empty array --- src/globals/fake-data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/globals/fake-data.js b/src/globals/fake-data.js index 79a2da7..63bd648 100644 --- a/src/globals/fake-data.js +++ b/src/globals/fake-data.js @@ -23,7 +23,7 @@ export const pages = { theme_style: true, type: 'page', link: `${window.location.origin}/preview`, - categories: [ ], + categories: [], featured_media: 0, permalink_template: `${window.location.origin}/preview`, preview_link: `${window.location.origin}/preview`, From fb02f068556f51385a987b38daee29ab10e50498 Mon Sep 17 00:00:00 2001 From: comerc Date: Sat, 12 Oct 2019 17:56:57 +0300 Subject: [PATCH 5/8] Added labels and "page" in types --- src/data/taxonomies.json | 62 ++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/src/data/taxonomies.json b/src/data/taxonomies.json index 2e28444..78b3257 100644 --- a/src/data/taxonomies.json +++ b/src/data/taxonomies.json @@ -3,10 +3,33 @@ "name": "Categories", "slug": "category", "description": "", - "types": [ - "post" - ], - "visibility": { "show_ui": false }, + "labels": { + "name": "Categories", + "singular_name": "Category", + "search_items": "Search Categories", + "popular_items": null, + "all_items": "All Categories", + "parent_item": "Parent Category", + "parent_item_colon": "Parent Category:", + "edit_item": "Edit Category", + "view_item": "View Category", + "update_item": "Update Category", + "add_new_item": "Add New Category", + "new_item_name": "New Category Name", + "separate_items_with_commas": null, + "add_or_remove_items": null, + "choose_from_most_used": null, + "not_found": "No categories found.", + "no_terms": "No categories", + "items_list_navigation": "Categories list navigation", + "items_list": "Categories list", + "most_used": "Most Used", + "back_to_items": "← Back to Categories", + "menu_name": "Categories", + "name_admin_bar": "category" + }, + "types": ["post", "page"], + "visibility": { "show_ui": true }, "hierarchical": true, "rest_base": "categories", "_links": { @@ -33,10 +56,33 @@ "name": "Tags", "slug": "post_tag", "description": "", - "types": [ - "post" - ], - "visibility": { "show_ui": false }, + "labels": { + "name": "Tags", + "singular_name": "Tag", + "search_items": "Search Tags", + "popular_items": "Popular Tags", + "all_items": "All Tags", + "parent_item": null, + "parent_item_colon": null, + "edit_item": "Edit Tag", + "view_item": "View Tag", + "update_item": "Update Tag", + "add_new_item": "Add New Tag", + "new_item_name": "New Tag Name", + "separate_items_with_commas": "Separate tags with commas", + "add_or_remove_items": "Add or remove tags", + "choose_from_most_used": "Choose from the most used tags", + "not_found": "No tags found.", + "no_terms": "No tags", + "items_list_navigation": "Tags list navigation", + "items_list": "Tags list", + "most_used": "Most Used", + "back_to_items": "← Back to Tags", + "menu_name": "Tags", + "name_admin_bar": "post_tag" + }, + "types": ["post", "page"], + "visibility": { "show_ui": true }, "hierarchical": false, "rest_base": "tags", "_links": { From a03b87fc8d0f736ec65fc334516fba3cecafb4fc Mon Sep 17 00:00:00 2001 From: comerc Date: Sat, 12 Oct 2019 18:00:46 +0300 Subject: [PATCH 6/8] Formatted code --- src/globals/api-routes.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/globals/api-routes.js b/src/globals/api-routes.js index 03aecec..70ea15e 100644 --- a/src/globals/api-routes.js +++ b/src/globals/api-routes.js @@ -185,7 +185,7 @@ export default [ { path: '/wp/v2/categories', method: 'POST', - handler({ payload: { name } }) { + handler ({ payload: { name } }) { return { id: window.lodash.random(1, 100000000), name, @@ -197,14 +197,14 @@ export default [ { path: '/wp/v2/tags', method: 'GET', - handler() { + handler () { return new window.Response(JSON.stringify(tags)); }, }, { path: '/wp/v2/tags', method: 'POST', - handler({ payload: { name } }) { + handler ({ payload: { name } }) { return { id: window.lodash.random(1, 100000000), name, From be70cf93b20a9bf8135e87db6c42ed5cf90bf47b Mon Sep 17 00:00:00 2001 From: comerc Date: Sat, 12 Oct 2019 18:06:22 +0300 Subject: [PATCH 7/8] Added categories, tags, _links for page --- src/globals/fake-data.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/globals/fake-data.js b/src/globals/fake-data.js index 63bd648..afa6954 100644 --- a/src/globals/fake-data.js +++ b/src/globals/fake-data.js @@ -23,13 +23,16 @@ export const pages = { theme_style: true, type: 'page', link: `${window.location.origin}/preview`, - categories: [], + categories: [1], + tags: [1, 2], featured_media: 0, permalink_template: `${window.location.origin}/preview`, preview_link: `${window.location.origin}/preview`, _links: { - 'wp:action-assign-categories': [], - 'wp:action-create-categories': [], + 'wp:action-create-categories': [{}], + 'wp:action-assign-categories': [{}], + 'wp:action-create-tags': [{}], + 'wp:action-assign-tags': [{}], }, }, post: { From 519ccac3c4707aec4a43a03352916871f089bff4 Mon Sep 17 00:00:00 2001 From: comerc Date: Sat, 12 Oct 2019 19:02:46 +0300 Subject: [PATCH 8/8] Fixed _links for post --- src/globals/fake-data.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/globals/fake-data.js b/src/globals/fake-data.js index afa6954..7b24574 100644 --- a/src/globals/fake-data.js +++ b/src/globals/fake-data.js @@ -63,10 +63,10 @@ export const pages = { permalink_template: `${window.location.origin}/preview`, preview_link: `${window.location.origin}/preview`, _links: { - 'wp:action-assign-categories': [], - 'wp:action-create-categories': [], - 'wp:action-create-tags': [], - 'wp:action-assign-tags': [], + 'wp:action-create-categories': [{}], + 'wp:action-assign-categories': [{}], + 'wp:action-create-tags': [{}], + 'wp:action-assign-tags': [{}], }, }, };