|
@@ -1,6 +1,7 @@
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
|
+using Microsoft.AspNetCore.Identity;
|
|
|
using Microsoft.JSInterop;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
@@ -17,14 +18,23 @@ namespace HyperCube.Pages
|
|
|
public partial class DocEdit : ComponentBase
|
|
|
{
|
|
|
[Parameter]
|
|
|
- public int docID { get; set; }
|
|
|
+ public int DocID { get; set; }
|
|
|
+
|
|
|
+ [Inject]
|
|
|
+ public NavigationManager NavigationManager { get; set; }
|
|
|
+ [Inject]
|
|
|
+ public IJSRuntime JsRuntime { get; set; }
|
|
|
+ [Inject]
|
|
|
+ public AuthenticationStateProvider AuthenticationStateProvider { get; set; }
|
|
|
+ [Inject]
|
|
|
+ public UserManager<IdentityUser> UserManager { get; set; }
|
|
|
|
|
|
const string FOLDER_NAME = "articles_storage";
|
|
|
const long MAX_FILE_SIZE = 5120000; //bytes
|
|
|
|
|
|
string transactionId;
|
|
|
- ArticleModel articleModelClone = new();
|
|
|
- ArticleModel articleModel = new();
|
|
|
+ ArticleModel articleClone = new();
|
|
|
+ ArticleModel article = new();
|
|
|
AccountModel currentAcc = new();
|
|
|
AccountModel initiatorAcc = new();
|
|
|
string status;
|
|
@@ -32,7 +42,7 @@ namespace HyperCube.Pages
|
|
|
string storageFolderPath;
|
|
|
MemoryStream memoryStream;
|
|
|
Modal modal { get; set; }
|
|
|
- string fullName { get { return FOLDER_NAME + "/" + articleModel.FilenameReal; } }
|
|
|
+ string fullName { get { return FOLDER_NAME + "/" + article.FilenameReal; } }
|
|
|
int editsCount;
|
|
|
|
|
|
bool IsSubmitDisabled = false;
|
|
@@ -46,7 +56,7 @@ namespace HyperCube.Pages
|
|
|
if (verifyContract != null)
|
|
|
{
|
|
|
Console.WriteLine($"VerifyContract found");
|
|
|
- transactionId = await verifyContract.Run(articleModel);
|
|
|
+ transactionId = await verifyContract.Run(article);
|
|
|
return transactionId;
|
|
|
}
|
|
|
else
|
|
@@ -67,7 +77,7 @@ namespace HyperCube.Pages
|
|
|
string path = AppDomain.CurrentDomain.BaseDirectory+@"wwwroot";
|
|
|
storageFolderPath = (Path.Combine(path, FOLDER_NAME));
|
|
|
Console.WriteLine("docedit OnInitializedAsync storageFolderPath2 " + storageFolderPath);
|
|
|
- if (docID > 0)
|
|
|
+ if (DocID > 0)
|
|
|
{
|
|
|
header = "Проверка материала";
|
|
|
|
|
@@ -76,14 +86,14 @@ namespace HyperCube.Pages
|
|
|
string stringSQL = $"SELECT articles.id, filename, article_name, authors, date_publish, annotation, keywords, action_type, rating " +
|
|
|
$"FROM articles " +
|
|
|
$"JOIN actions_history ON actions_history.article_id = articles.id " +
|
|
|
- $"WHERE articles.id={docID} " +
|
|
|
+ $"WHERE articles.id={DocID} " +
|
|
|
$"ORDER BY actions_history.id DESC LiMIT 1";
|
|
|
- articleModelClone = await dbCon.SQLSelectArticle(stringSQL);
|
|
|
- articleModel = (ArticleModel)articleModelClone.Clone();
|
|
|
+ articleClone = await dbCon.SQLSelectArticle(stringSQL);
|
|
|
+ article = (ArticleModel)articleClone.Clone();
|
|
|
|
|
|
- string initiator = await articleModel.GetInitiatorUUID();
|
|
|
+ string initiator = await article.GetInitiatorUUID();
|
|
|
initiatorAcc = AccountModel.Find(initiator);
|
|
|
- status = $"Article ID={docID} loaded, status: {articleModel.Status}, initiator: {initiatorAcc.Name}";
|
|
|
+ status = $"Article ID={DocID} loaded, status: {article.Status}, initiator: {initiatorAcc.Name}";
|
|
|
}
|
|
|
else
|
|
|
header = "Загрузка материала";
|
|
@@ -113,65 +123,65 @@ namespace HyperCube.Pages
|
|
|
long id;
|
|
|
string stringSQL;
|
|
|
|
|
|
- Console.WriteLine($"HandleValidSubmit, docID: {docID}");
|
|
|
+ Console.WriteLine($"HandleValidSubmit, docID: {DocID}");
|
|
|
|
|
|
- if (docID > 0)
|
|
|
+ if (DocID > 0)
|
|
|
{
|
|
|
- id = docID;
|
|
|
+ id = DocID;
|
|
|
stringSQL = $"UPDATE articles " +
|
|
|
- $"SET filename='{articleModel.Filename}', article_name='{articleModel.Name}', authors='{articleModel.Authors}', " +
|
|
|
- $"date_publish='{articleModel.PublishDate:yyyy-MM-dd}', annotation='{articleModel.Annotation}', " +
|
|
|
- $"keywords='{articleModel.Keywords}', rating={articleModel.Rating}, file_hash={articleModel.FileHashSum} " +
|
|
|
- $"WHERE id={docID}";
|
|
|
+ $"SET filename='{article.Filename}', article_name='{article.Name}', authors='{article.Authors}', " +
|
|
|
+ $"date_publish='{article.PublishDate:yyyy-MM-dd}', annotation='{article.Annotation}', " +
|
|
|
+ $"keywords='{article.Keywords}', rating={article.Rating}, file_hash='{article.FileHashSum}' " +
|
|
|
+ $"WHERE id={DocID}";
|
|
|
await dbCon.SQLInsert(stringSQL);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
stringSQL = $"INSERT INTO articles (filename, article_name, authors, date_publish, annotation, keywords, file_hash) " +
|
|
|
- $"VALUES ('{articleModel.Filename}', '{articleModel.Name}', '{articleModel.Authors}', '{articleModel.PublishDate:yyyy-MM-dd}'," +
|
|
|
- $"'{articleModel.Annotation}', '{articleModel.Keywords}', '{articleModel.FileHashSum}')";
|
|
|
+ $"VALUES ('{article.Filename}', '{article.Name}', '{article.Authors}', '{article.PublishDate:yyyy-MM-dd}'," +
|
|
|
+ $"'{article.Annotation}', '{article.Keywords}', '{article.FileHashSum}')";
|
|
|
id = await dbCon.SQLInsert(stringSQL);
|
|
|
NewProjectSmopp(id);
|
|
|
}
|
|
|
|
|
|
/// tmp
|
|
|
- int action_type = docID > 0 ? 2 : 1;
|
|
|
+ int action_type = DocID > 0 ? 2 : 1;
|
|
|
|
|
|
stringSQL = $"INSERT INTO actions_history (article_id, action_type, acc_id) " +
|
|
|
$"VALUES ('{id}', '{action_type}', '{currentAcc.UUID}')";
|
|
|
await dbCon.SQLInsert(stringSQL);
|
|
|
|
|
|
- Dictionary<string, PropertyInfo> propDict = Compare.SimpleCompare<ArticleModel>(articleModel, articleModelClone);
|
|
|
+ Dictionary<string, PropertyInfo> propDict = Compare.SimpleCompare<ArticleModel>(article, articleClone);
|
|
|
foreach (KeyValuePair<string, PropertyInfo> prop in propDict)
|
|
|
{
|
|
|
//Console.WriteLine($"property name: {prop.Key}, value: {prop.Value.GetValue(articleModel, null)}");
|
|
|
|
|
|
stringSQL = $"INSERT INTO articles_edit_log (article_id, acc_id, field_name, field_prevvalue, field_newvalue) " +
|
|
|
- $"VALUES ('{id}', '{currentAcc.UUID}', '{prop.Key}', '{prop.Value.GetValue(articleModelClone, null)}', '{prop.Value.GetValue(articleModel, null)}')";
|
|
|
+ $"VALUES ('{id}', '{currentAcc.UUID}', '{prop.Key}', '{prop.Value.GetValue(articleClone, null)}', '{prop.Value.GetValue(article, null)}')";
|
|
|
await dbCon.SQLInsert(stringSQL);
|
|
|
}
|
|
|
|
|
|
//dbCon.Close();
|
|
|
|
|
|
- if (docID > 0)
|
|
|
+ if (DocID > 0)
|
|
|
{
|
|
|
status = propDict.Count > 0 ? "All changes saved, article has veryfied." : "Article verifyed without any changes.";
|
|
|
transactionId = await Verify();
|
|
|
Console.WriteLine("transactionId found " + transactionId);
|
|
|
|
|
|
///tmp
|
|
|
- editsCount = await articleModel.GetEditsCount(currentAcc.UUID);
|
|
|
+ editsCount = await article.GetEditsCount(currentAcc.UUID);
|
|
|
modal.Open();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- string fullpath = Path.Combine(storageFolderPath, $"{id}_{articleModel.Filename}");
|
|
|
+ string fullpath = Path.Combine(storageFolderPath, $"{id}_{article.Filename}");
|
|
|
Directory.CreateDirectory(storageFolderPath);
|
|
|
FileStream fs = new(fullpath, FileMode.Create, FileAccess.Write);
|
|
|
memoryStream.Position = 0;
|
|
|
await memoryStream.CopyToAsync(fs);
|
|
|
|
|
|
- Console.WriteLine($"User has saved new article data, {id}_{articleModel.Filename}, memory size:{memoryStream.Length}b, file size: {fs.Length}b");
|
|
|
+ Console.WriteLine($"User has saved new article data, {id}_{article.Filename}, memory size:{memoryStream.Length}b, file size: {fs.Length}b");
|
|
|
memoryStream.Close();
|
|
|
fs.Close();
|
|
|
|
|
@@ -212,10 +222,10 @@ namespace HyperCube.Pages
|
|
|
|
|
|
if (count < 1)
|
|
|
{
|
|
|
- articleModelClone = DocParse.ReadPDF(memoryStream);
|
|
|
- articleModelClone.Filename = file.Name;
|
|
|
- articleModelClone.FileHashSum = hash;
|
|
|
- articleModel = (ArticleModel)articleModelClone.Clone();
|
|
|
+ articleClone = DocParse.ReadPDF(memoryStream);
|
|
|
+ articleClone.Filename = file.Name;
|
|
|
+ articleClone.FileHashSum = hash;
|
|
|
+ article = (ArticleModel)articleClone.Clone();
|
|
|
|
|
|
IsSubmitDisabled = false;
|
|
|
}
|