浏览代码

Merge branch 'master' of http://dev.prmsys.net:3001/Rimmon/HyperCube

Rimmon 4 年之前
父节点
当前提交
de49ab13cf
共有 4 个文件被更改,包括 61 次插入34 次删除
  1. 14 1
      Models/ArticleModel.cs
  2. 17 14
      MySQLConnector.cs
  3. 6 4
      Pages/DocEdit.razor
  4. 24 15
      Pages/Verifying.razor

+ 14 - 1
Models/ArticleModel.cs

@@ -1,9 +1,22 @@
 using System;
+using System.ComponentModel;
 using System.ComponentModel.DataAnnotations;
 
 namespace HyperCube.Models
 {
-    public enum ArticleStatus { New = 0, Added, Edited, Verified, Rejected, Deleted }
+    public enum ArticleStatus {
+        [Display(Name = "Новая")]
+        New = 0,
+        [Display(Name = "Добавлена")]
+        Added,
+        [Display(Name = "Отредактирована")]
+        Edited,
+        [Display(Name = "Проверена")]
+        Verified,
+        [Display(Name = "Отклонена")]
+        Rejected,
+        [Display(Name = "Удалена")]
+        Deleted }
 
     public class ArticleModel : ICloneable
     {

+ 17 - 14
MySQLConnector.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Threading.Tasks;
+using HyperCube.Models;
 using MySql.Data.MySqlClient;
 
 namespace HyperCube
@@ -58,10 +59,10 @@ namespace HyperCube
             return lastID;
         }
 
-        public async Task<Dictionary<int, Models.SmartContract>> SQLSelectContracts()
+        public async Task<Dictionary<int, SmartContract>> SQLSelectContracts()
         {
             string sql = "select * from smart_contracts";
-            Dictionary<int, Models.SmartContract> contracts = new();
+            Dictionary<int, SmartContract> contracts = new();
 
             bool connected = IsConnect();
             if (connected)
@@ -90,9 +91,9 @@ namespace HyperCube
             return null;
         }
 
-        public async Task<Dictionary<int, Models.ArticleModel>> SQLSelectArticles(string sql)
+        public async Task<Dictionary<int, ArticleModel>> SQLSelectArticles(string sql)
         {
-            Dictionary<int, Models.ArticleModel> articleModels = new();
+            Dictionary<int, ArticleModel> articleModels = new();
             Models.ArticleModel articleModel;
 
             bool connected = IsConnect();
@@ -101,23 +102,24 @@ namespace HyperCube
                 SQLcom = new(sql, Connection);
                 MySqlDataReader rdr = SQLcom.ExecuteReader();
 
-                while (rdr.Read())
-                {
-                    //Console.WriteLine("{0} {1} {2} {3} {4}", rdr.GetInt32(0), rdr.GetString(1),
-                    //        rdr.GetString(2), rdr.GetDateTime(3), rdr.GetString(4));
-
+                while (rdr.Read()) ///id, filename, article_name, date_publish, action_type/status
+                {                    
                     articleModel = new();
+                    int id = rdr.GetInt32(0);
                     articleModel.Filename = rdr.GetString(1);
                     articleModel.Name = rdr.GetString(2);
                     articleModel.PublishDate = rdr.GetDateTime(3);
                     articleModel.Authors = rdr.GetString(4);
+                    articleModel.Status = (ArticleStatus)rdr.GetInt32(5);
+
+                    if (articleModels.ContainsKey(id))
+                        continue;
 
-                    articleModels.Add(rdr.GetInt32(0), articleModel);
+                    articleModels.Add(id, articleModel);
                 }
 
                 await Task.WhenAll();
                 rdr.Close();
-                //Console.WriteLine("End reading DB");
                 return articleModels;
             }
             else
@@ -126,9 +128,9 @@ namespace HyperCube
             return null;
         }
 
-        public async Task<Models.ArticleModel> SQLSelectArticle(string sql)
+        public async Task<ArticleModel> SQLSelectArticle(string sql)
         {
-            Models.ArticleModel articleModel = new();
+            ArticleModel articleModel = new();
 
             bool connected = IsConnect();
             if (connected)
@@ -136,7 +138,7 @@ namespace HyperCube
                 SQLcom = new(sql, Connection);
                 MySqlDataReader rdr = SQLcom.ExecuteReader();
 
-                while (rdr.Read())  //id, filename, article_name, authors, date_publish, annotation, keywords
+                while (rdr.Read())  ///id, filename, article_name, authors, date_publish, annotation, keywords, action_type/status
                 {
                     articleModel.Filename = rdr.GetString(1);
                     articleModel.Name = rdr.GetString(2);
@@ -144,6 +146,7 @@ namespace HyperCube
                     articleModel.PublishDate = rdr.GetDateTime(4);
                     articleModel.Annotation = rdr.GetString(5);
                     articleModel.Keywords = rdr.GetString(6);
+                    articleModel.Status = (ArticleStatus)rdr.GetInt32(7);
                 }
                 await Task.WhenAll();
                 rdr.Close();

+ 6 - 4
Pages/DocEdit.razor

@@ -75,19 +75,21 @@
 
             MySQLConnector dbCon = MySQLConnector.Instance();
 
-            string stringSQL = $"SELECT id, filename, article_name, authors, date_publish, annotation, keywords " +
+            string stringSQL = $"SELECT articles.id, filename, article_name, authors, date_publish, annotation, keywords, action_type " +
                 $"FROM articles " +
-                $"WHERE id={docID}";
+                $"JOIN actions_history ON actions_history.article_id = articles.id " +
+                $"WHERE articles.id={docID} " +
+                $"ORDER BY actions_history.id DESC LiMIT 1";
             oldArticleModel = await dbCon.SQLSelectArticle(stringSQL);
             articleModel = (ArticleModel)oldArticleModel.Clone();
 
-            status = $"Article ID={docID} loaded.";
+            status = $"Article ID={docID} loaded, status: {articleModel.Status}";
         }
         else
             header = "Загрузка материала";
 
 
-        AccountModel account = await GetCurrentAcc();        
+        AccountModel account = await GetCurrentAcc();
         //header += $", uuid:{account.UUID}, name: {account.Name}";
     }
 

+ 24 - 15
Pages/Verifying.razor

@@ -1,5 +1,7 @@
 @page "/verifying"
-@using Microsoft.AspNetCore.Components.Web;
+@using System.ComponentModel.DataAnnotations;
+@using System.Linq;
+@using System.Reflection;
 @attribute [Authorize]
 
 <h1>Верификация</h1>
@@ -12,20 +14,20 @@
             <th>Название</th>
             <th>Дата издания</th>
             <th>Авторы</th>
-            @*<th></th>*@
+            <th>Статус</th>
         </tr>
     </thead>
     <tbody>
         @foreach (var articleModel in articleModels)
         {
-        <tr>
-            <td>@(counter++)</td>
-            <td>@articleModel.Value.Filename</td>
-            <td><a href="@($"/docedit/{articleModel.Key}")">@articleModel.Value.Name</a></td>
-            <td>@articleModel.Value.PublishDate.ToString("d")</td>
-            <td>@articleModel.Value.Authors</td>
-            @*<td><button @onclick="(() => VerifyArticle(articleModel.Key))">Верифицировать</button></td>*@
-        </tr>
+            <tr>
+                <td>@(counter++)</td>
+                <td>@articleModel.Value.Filename</td>
+                <td><a href="@($"/docedit/{articleModel.Key}")">@articleModel.Value.Name</a></td>
+                <td>@articleModel.Value.PublishDate.ToString("d")</td>
+                <td>@articleModel.Value.Authors</td>
+                <td>@GetDisplayName(articleModel.Value.Status)</td>
+            </tr>
         }
     </tbody>
 </table>
@@ -39,7 +41,10 @@
     {
         MySQLConnector dbCon = MySQLConnector.Instance();
 
-        string stringSQL = $"SELECT id, filename, article_name, date_publish, authors FROM articles";
+        string stringSQL = $"SELECT a.id, filename, article_name, date_publish, authors, ah.action_type " +
+                $"FROM articles a " +
+                $"LEFT JOIN actions_history ah ON a.id = ah.article_id " +
+                $"AND EXISTS (SELECT 1 FROM actions_history ah1 WHERE ah.article_id = ah1.article_id HAVING MAX(ah1.date_add) = ah.date_add)";
         articleModels = await dbCon.SQLSelectArticles(stringSQL);
 
         dbCon.Close();
@@ -47,8 +52,12 @@
         //status = results;
     }
 
-    //private void VerifyArticle(int id)
-    //{
-    //    Console.WriteLine($"Verifyed arcticle ID: {id}!");
-    //}
+    private static string GetDisplayName(Enum enumValue)
+    {
+        return enumValue.GetType()
+                        .GetMember(enumValue.ToString())
+                        .First()
+                        .GetCustomAttribute<DisplayAttribute>()
+                        .GetName();
+    }
 }