Browse Source

component dropown > 드롭다운 컴포넌트 옵션 추가

김보경 5 years ago
parent
commit
77aea3bf7d
3 changed files with 25 additions and 5 deletions
  1. 10 4
      pages/instructor/blogs/index.vue
  2. 12 1
      pages/instructor/options.js
  3. 3 0
      store/instructor/blog.js

+ 10 - 4
pages/instructor/blogs/index.vue

@@ -62,7 +62,7 @@
                     </span>
                     <dropdown 
                       @optionChanged="handleOption($event, pBlog)"
-                      :items="publishedOptions" />
+                      :items="publishedOptions(pBlog.featured)" />
                     <!-- Dropdown with menu here -->
                   </div>
                 </div>
@@ -98,9 +98,6 @@ export default {
       published : ({instructor}) => instructor.blog.items.published,
       drafts : ({instructor}) => instructor.blog.items.drafts,
     }),
-    publishedOptions() {
-      return createPublishedOptions()
-    },
     draftsOptions() {
       return createDraftsOptions()
     }
@@ -115,6 +112,15 @@ export default {
         // alert('Deleting Blog')
         this.displayDeleteWarning(blog)
       }
+      if (command === commands.TOGGLE_FEATURE) {
+        this.updateBlog(blog)
+      }
+    },
+    updateBlog(blog) {
+      this.$store.dispatch('instructor/blog/updatePublishedBlog')
+    },
+    publishedOptions(isFeatured) {
+      return createPublishedOptions(isFeatured)
     },
     displayDeleteWarning(blog) {
       const isConfirm = confirm('Are you sure you want to delete blog ?')

+ 12 - 1
pages/instructor/options.js

@@ -2,6 +2,7 @@
 export const commands = {
   'DELETE_BLOG': 'DELETE_BLOG',
   'EDIT_BLOG': 'EDIT_BLOG',
+  'TOGGLE_FEATURE': 'TOGGLE_FEATURE'
 }
 
 const createOption = (name, command) => ({name, command})
@@ -10,6 +11,9 @@ const createOption = (name, command) => ({name, command})
 // Published Blogs
 const DELETE_BLOG = createOption('Delete Blog', commands.DELETE_BLOG)
 const EDIT_BLOG = createOption('Edit Blog', commands.EDIT_BLOG)
+const FEATURE_BLOG = createOption('Feature Blog', commands.TOGGLE_FEATURE)
+const UN_FEATURE_BLOG = createOption('Un-Feature Blog', commands.TOGGLE_FEATURE)
+
 
 // Options
 // Drafts Blogs
@@ -17,5 +21,12 @@ const DELETE_DRAFT = createOption('Delete Draft', commands.DELETE_BLOG)
 const EDIT_DRAFT = createOption('Edit Draft', commands.EDIT_BLOG)
 
 
-export const createPublishedOptions = () => [EDIT_BLOG, DELETE_BLOG]
+export const createPublishedOptions = (isFeatured) => {
+  const options = [EDIT_BLOG, DELETE_BLOG]
+
+  isFeatured ? options.push(UN_FEATURE_BLOG) : options.push(FEATURE_BLOG)
+
+  return options
+}
+
 export const createDraftsOptions = () => [EDIT_DRAFT, DELETE_DRAFT]

+ 3 - 0
store/instructor/blog.js

@@ -66,6 +66,9 @@ export const actions = {
     commit('deleteBlog', {resource, index})
     return true
   },
+  updatePublishedBlog(blog) {
+    alert('FEATURING BLOG')
+  },
   async updateBlog({commit, state}, {data, id}) {
     console.log('instructor/blog.js actions updateBlog call axios.$patch-> Id, data')
     const blog = await this.$axios.$patch(`/api/v1/blogs/${id}`, data)