OSDN Git Service

fix story editor to work
authorhylom <hylom@users.sourceforge.jp>
Fri, 10 May 2019 11:40:35 +0000 (20:40 +0900)
committerhylom <hylom@users.sourceforge.jp>
Fri, 10 May 2019 11:40:35 +0000 (20:40 +0900)
src/newslash_web/lib/Newslash/Web/Controller/API/Story.pm
src/newslash_web/lib/Newslash/Web/Controller/Admin/Story.pm
src/newslash_web/public/js/article-item2.js
src/newslash_web/templates/admin/story/edit.html.tt2
src/newslash_web/templates/common/article/article.html.tt2
src/newslash_web/templates/common/article/editor.html.tt2

index 46b09bc..c6cad37 100644 (file)
@@ -74,6 +74,13 @@ sub post {
         $message = "invalid_createtime";
     }
     else {
+        # convert localtime to GMT
+        if ($user && $user->{config}->{ui}->{offset_sec}) {
+            my $offset_sec = $user->{config}->{ui}->{offset_sec} || 0;
+            if ($offset_sec) {
+                $dt->subtract(seconds => $offset_sec);
+            }
+        }
         $params->{time} = DateTime::Format::MySQL->format_datetime($dt);
     }
 
@@ -158,9 +165,7 @@ sub post {
     if ($item->{stoid}) {
         # update story
         $params->{stoid} = $item->{stoid};
-        my $rs = $stories->update(user => $user, %$params);
-        $stoid = $rs ? $item->{stoid} : 0;
-        $sid = $rs ? $item->{sid} : 0;
+        ($sid, $stoid) = $stories->update(user => $user, %$params);
     }
     else {
         # create story
@@ -183,7 +188,7 @@ sub post {
     }
 
     # post succeeded, return result
-    $c->render(json => {type => "story", id => $stoid, sid => $sid});
+    $c->render(json => {type => "story", id => $stoid, sid => $sid, url_id => $sid});
     $c->event_que->emit("story", "post", $user->{uid}, $stoid);
     $c->stats->add_event_counter("story_create");
     return;
index f5d9d86..c02c2fc 100644 (file)
@@ -8,9 +8,21 @@ sub edit {
     my $authors = $users->select(author => 1);
 
     my $sub_id = $c->param('subid');
+    my $stoid = $c->param('stoid');
     my $source = {};
+    my $page = {};
 
-    if ($sub_id) {
+    if ($stoid) {
+        my $story = $c->model('stories')->select(stoid => $stoid);
+        if ($story) {
+            $source->{type} = "story";
+            $source->{id} = $stoid;
+            $source->{item} = $story;
+            $page->{type} = "story";
+            $page->{stoid} = $stoid;
+        }
+    }
+    elsif ($sub_id) {
         my $sub = $c->model('submissions')->select(submission_id => $sub_id);
         if ($sub) {
             $source->{type} = "submission";
@@ -19,7 +31,7 @@ sub edit {
         }
     }
 
-    $c->render(authors => $authors, source => $source);
+    $c->render(authors => $authors, source => $source, page => $page);
 }
 
 
index 45c84ae..97334b6 100644 (file)
@@ -228,14 +228,17 @@ articleItem.init = function init () {
     this.$newslash.post(type, postData, {csrfToken: this.csrfToken},
                         (response) => { // success
                           this.message = "";
-                          var id = response.body.id;
+                          var id = response.body.url_id || response.body.id;
                           var type = response.body.type;
                           var url = '/' + type + '/' + id;
                           
                           // check if new post
                           if (!postData.id) {
                             this.createdUrl = url;
-                            this.item.subid = id;
+                            if (page.type == "submission") {
+                              this.item.subid = id;
+                            }
+                            this.editor.id = response.body.id;
                           }
                           this.message = "";
                           this.mode = "posted";
@@ -264,6 +267,13 @@ articleItem.init = function init () {
       postData.item[k] = vm.editor[k];
     });
 
+    // prepare ID
+    if (vm.editor.id) {
+      if (page.type == "story") {
+        postData.item.stoid = vm.editor.id;
+      }
+    }
+
     return postData;
   }
 
@@ -389,16 +399,30 @@ articleItem.init = function init () {
       c.item.content_type = "story";
 
       c.$newslash.getStoryByID(page.stoid,
-        (resp) => { // succeed
-          for (k in resp.body.item) {
-            c.editor.item[k] = resp.body.item[k];
+        (resp) => {
+          // succeed
+          var item = resp.body.item;
+          for (var k in c.editor) {
+            if (item[k] !== undefined) {
+              c.editor[k] = item[k];
+            }
+          }
+          // convert tags to tags_string
+          if (item.tags) {
+            var tagnames = item.tags.map(tag => tag.tagname);
+            c.editor.tags_string = tagnames.join(" ");
           }
+          // TODO: related stories
+          // convert public to display
+          c.editor.display = (item.public == "yes");
+          c.editor.createtime = nsUtil.formatToLocalISOString(nsUtil.decodeMySQLDateTime(item.create_time));
+          c.editor.id = item.stoid;
         },
         (resp) => { //failed
           c.message = resp.body.message;
         });
     }
-    
+      
     // submission to story mode
     if (c.item.submission_id) {
       c.$newslash.getSubmissionByID(c.item.submission_id, 
index 6dbbe49..aa17155 100644 (file)
@@ -18,7 +18,8 @@
 <script>
   editor.run({ type: 'story',
   el: '#story-editor',
-  [% IF source.id %] submissionID: [% source.id %], [% END %]
+  [%- IF source.type == "submission" %] submissionID: [% source.id %], [% END %]
+  [%- IF source.type == "story" %] storyID: [% source.id %], [% END %]
   });
 </script>
 
index 32e77d5..b6676f5 100644 (file)
@@ -86,10 +86,10 @@ END;
       </button>
       [%- END -%]
       [%- IF x_template || item.content_type == 'story' && user.is_admin || user.editor  -%]
-      <a href="/story/edit?stoid=[% item. stoid %]">[編集]</a>
+      <a href="/admin/story/edit?stoid=[% item. stoid %]">[編集]</a>
       [%- END -%]
       [%- IF item.content_type == 'submission' && (user.author || x_template) -%]
-      [<a href="/admin/story/edit?subid=[% item.submission_id %]">accept</a>]
+      [<a href="/admin/story/edit?subid=[% item.submission_id %]">[accept]</a>]
       [%- END -%]
     </div>
 
index b2d8a54..667e8d5 100644 (file)
@@ -1,6 +1,7 @@
 <div class="content-editor-wrap">
   <div class="alert alert-info post-done" v-if="mode == 'posted'">
     投稿を行いました。URL:<A :href="createdUrl" v-text="createdUrl"></a>
+    <span v-if="item.content_type == 'story'"><a href="#" @click="leavePreview">[再編集]</a></span>
   </div>
   <div class="alert alert-info post-error-message" v-show="message">
     <div v-if="message == 'duplicated_post'">エラー:すでに同じ内容が投稿されています</div>