From b845ec25e7107a384067b0f401a2006b2f5d507b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=98=89=E7=A5=A5=20=E8=A9=B9?= Date: Tue, 7 Nov 2023 19:30:12 +0800 Subject: [PATCH] updates --- Controllers/AuthApiController.cs | 209 ++++++++++++ Controllers/HomeController.cs | 16 + Models/DbTableClass.cs | 47 +++ Views/Home/OptionList.cshtml | 157 +++++++++ Views/Shared/_LooperLayout.cshtml | 5 +- .../assets/javascript/custom/optionlist.js | 300 ++++++++++++++++++ 6 files changed, 733 insertions(+), 1 deletion(-) create mode 100644 Views/Home/OptionList.cshtml create mode 100644 wwwroot/assets/javascript/custom/optionlist.js diff --git a/Controllers/AuthApiController.cs b/Controllers/AuthApiController.cs index a40287d..293c57d 100644 --- a/Controllers/AuthApiController.cs +++ b/Controllers/AuthApiController.cs @@ -57,6 +57,199 @@ namespace Journeys_WantHome.Controllers this._httpContextAccessor = httpContextAccessor; } + [Route("addEditDelItem")] + public ActionResult AddEditDelItem(IFormCollection obj) { + optionItemResult ret = new optionItemResult(); + + authToken token = new authToken(this._httpContextAccessor); + if (token.user_isLogin == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + ret.ret = "no"; + ret.err_code = "99999"; + ret.message = "非登入狀態!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (token.user_perm != "system") + { + ret.ret = "no"; + ret.err_code = "90001"; + ret.message = "此帳號無此api使用權限!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + string option_uid = obj["option_uid"].ToString(); + string optionItem_uid = obj["optionItem_uid"].ToString(); + string optionItem_name = obj["optionItem_name"].ToString(); + string method = obj["method"].ToString(); + + + if (option_uid == "") + { + ret.ret = "no"; + ret.err_code = "00001"; + ret.message = "無option_uid資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "") { + ret.ret = "no"; + ret.err_code = "0002"; + ret.message = "無method資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "get") { + optionItem item = conn.QueryFirstOrDefault("select * from optionItem where optionItem_ishide = 'N' and option_uid = @option_uid and optionItem_uid = @optionItem_uid", new { option_uid = option_uid, optionItem_uid = optionItem_uid}); + + if (item == null) { + ret.ret = "no"; + ret.err_code = "0003"; + ret.message = "無此筆資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + ret.ret = "yes"; + ret.optionItem = item; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "add") { + if (optionItem_name == "") { + ret.ret = "no"; + ret.err_code = "0004"; + ret.message = "無項目名稱!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + optionItem item = conn.QueryFirstOrDefault("select * from optionItem where optionItem_ishide = 'N' and option_uid = @option_uid and optionItem_name = @optionItem_name", new { option_uid = option_uid, optionItem_name = optionItem_name}); + + if (item != null) + { + ret.ret = "no"; + ret.err_code = "0005"; + ret.message = "此項目名稱已存在!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + List itemsList = conn.Query("select * from optionItem where optionItem_ishide = 'N' and option_uid = @option_uid", new { option_uid = option_uid}).ToList(); + + optionItem_uid = "item_" + GlobalClass.CreateRandomCode(8); + item = new optionItem(); + + item.option_uid = option_uid; + item.optionItem_uid = optionItem_uid; + item.optionItem_name = optionItem_name; + item.optionItem_ishide = "N"; + item.optionItem_userId = token.user_id; + item.optionItem_order = itemsList.Count + 1; + + conn.Insert(item); + + ret.ret = "yes"; + ret.optionItem = item; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "edit") { + if (optionItem_name == "") + { + ret.ret = "no"; + ret.err_code = "0004"; + ret.message = "無項目名稱!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + optionItem item = conn.QueryFirstOrDefault("select * from optionItem where optionItem_ishide = 'N' and option_uid = @option_uid and optionItem_name = @optionItem_name and optionItem_uid <> @optionItem_uid", new { option_uid = option_uid, optionItem_name = optionItem_name, optionItem_uid = optionItem_uid }); + + if (item != null) + { + ret.ret = "no"; + ret.err_code = "0005"; + ret.message = "此修改後項目名稱已被使用!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + optionItem editItem = conn.QueryFirstOrDefault("select * from optionItem where optionItem_ishide = 'N' and option_uid = @option_uid and optionItem_uid = @optionItem_uid", new { option_uid = option_uid, optionItem_uid = optionItem_uid}); + + if (editItem == null) { + ret.ret = "no"; + ret.err_code = "0003"; + ret.message = "無此筆資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + editItem.optionItem_name = optionItem_name; + editItem.optionItem_userId = token.user_id; + editItem.optionItem_modifydate = DateTime.Now; + + conn.Update(editItem); + ret.ret = "yes"; + ret.optionItem = editItem; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "del") { + optionItem editItem = conn.QueryFirstOrDefault("select * from optionItem where optionItem_ishide = 'N' and option_uid = @option_uid and optionItem_uid = @optionItem_uid", new { option_uid = option_uid, optionItem_uid = optionItem_uid }); + + if (editItem == null) + { + ret.ret = "no"; + ret.err_code = "0003"; + ret.message = "無此筆資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + editItem.optionItem_userId = token.user_id; + editItem.optionItem_modifydate = DateTime.Now; + editItem.optionItem_ishide = "Y"; + + conn.Update(editItem); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [Route("optionItemList")] + public ActionResult OptionItemList(IFormCollection obj) { + optionListResult ret = new optionListResult(); + + authToken token = new authToken(this._httpContextAccessor); + if (token.user_isLogin == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + ret.ret = "no"; + ret.err_code = "99999"; + ret.message = "非登入狀態!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (token.user_perm != "system") + { + ret.ret = "no"; + ret.err_code = "90001"; + ret.message = "此帳號無此api使用權限!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + string option_uid = obj["option_uid"].ToString(); + + if (option_uid == "") { + ret.ret = "no"; + ret.err_code = "00001"; + ret.message = "無option_uid資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + ret.optionItems = conn.Query("select * from optionItem where optionItem_ishide = 'N' and option_uid = @option_uid order by optionItem_order ", new { option_uid = option_uid }).ToList(); + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + [Route("addEditGetUser")] public ActionResult AddEditGetUser(IFormCollection obj) { updateUserResult ret = new updateUserResult(); @@ -610,5 +803,21 @@ namespace Journeys_WantHome.Controllers public string message = ""; public user user = new user(); } + + public class optionListResult + { + public string ret = "no"; + public string err_code = "0000"; + public string message = ""; + public List optionItems = new List(); + } + + public class optionItemResult + { + public string ret = "no"; + public string err_code = "0000"; + public string message = ""; + public optionItem optionItem = new optionItem(); + } } } diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index 25a7060..b6cf7ed 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -22,6 +22,22 @@ namespace Journeys_WantHome.Controllers this._objToken = new authToken(this._httpContextAccessor); } + public IActionResult OptionList() + { + if (checkToken() == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + return Redirect("~/Root/Login"); + } + + if (this._objToken.user_perm != "system") + { + return Redirect("~/"); + } + + return View(); + } + public IActionResult UserList() { if (checkToken() == false) diff --git a/Models/DbTableClass.cs b/Models/DbTableClass.cs index 5cfd553..052df29 100644 --- a/Models/DbTableClass.cs +++ b/Models/DbTableClass.cs @@ -8,6 +8,53 @@ using Newtonsoft.Json.Linq; public class DbTableClass { + [Table("optionItem")] + public class optionItem + { + [JsonIgnore] + [Key] + public int optionItem_sn { get; set; } + + public string option_uid { get; set; } = ""; + + public string optionItem_uid { get; set; } = ""; + + public string optionItem_name { get; set; } = ""; + + public string optionItem_ishide { get; set; } = "N"; + + public int optionItem_order { get; set; } = 999; + + public DateTime optionItem_createdate { get; set; } = DateTime.Now; + + public DateTime optionItem_modifydate { get; set; } = DateTime.Now; + + public string optionItem_userId { get; set; } = ""; + + } + + + + [Table("option")] + public class option + { + [JsonIgnore] + [Key] + public int option_sn { get; set; } + + public string option_uid { get; set; } = ""; + + public string option_name { get; set; } = ""; + + public string option_ishide { get; set; } = "N"; + + public DateTime option_createdate { get; set; } = DateTime.Now; + + public DateTime option_modifydate { get; set; } = DateTime.Now; + + } + + [Table("token")] public class token { diff --git a/Views/Home/OptionList.cshtml b/Views/Home/OptionList.cshtml new file mode 100644 index 0000000..6bc8027 --- /dev/null +++ b/Views/Home/OptionList.cshtml @@ -0,0 +1,157 @@ +@* + For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 +*@ +@{ + Layout = "_LooperLayout"; +} + +@section Style { + +} + +@section Script { + + + +} + +
+ +
+ +

選項項目資料維護

+
+ +
+ + + +
+ +
+ +
+
KOL成員類型
+
+ +
    + +
+
+ + +
+
+ +
+ +
+
KOL類型
+
+ +
    +
+
+ + +
+
+ +
+ +
+
粉絲輪廓
+
+ +
    +
+
+ + +
+
+ +
+ +
+
合作形式
+
+ +
    +
+
+ + +
+
+ +
+ +
+
媒體平台
+
+ +
    +
+
+ + +
+
+
+
+
+ + +
+ +
\ No newline at end of file diff --git a/Views/Shared/_LooperLayout.cshtml b/Views/Shared/_LooperLayout.cshtml index 520583c..80f2fdf 100644 --- a/Views/Shared/_LooperLayout.cshtml +++ b/Views/Shared/_LooperLayout.cshtml @@ -133,7 +133,10 @@ Auth diff --git a/wwwroot/assets/javascript/custom/optionlist.js b/wwwroot/assets/javascript/custom/optionlist.js new file mode 100644 index 0000000..2780981 --- /dev/null +++ b/wwwroot/assets/javascript/custom/optionlist.js @@ -0,0 +1,300 @@ +var tmpNestableObj; + +$(document).ready(function () { + loadKolMakeupList(); + loadKolStyleList(); + loadFansTypeList(); + loadCooperateTypeList(); + loadMediaList(); + + $('#optionItemDialogSaveBtn').click(function () { + var method = $('#method').val(); + var option_uid = $('#option_uid').val(); + var optionItem_uid = $('#optionItem_uid').val(); + var optionItem_name = $('#optionItem_name').val(); + + if (method == 'add') { + if (optionItem_name == '') { + alert('請輸入項目名稱!'); + return; + } + + var formData = { + option_uid: option_uid, + optionItem_name: optionItem_name, + method: method + } + + $.ajax({ + url: "/AuthApi/addEditDelItem", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.optionItem; + + tmpNestableObj.children().append(optionItemHtml(obj)); + + $('#optionItemModal').modal('toggle'); + + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); + } + }); +}); + +//$(document).on('theme:init', function () { +// //loadKolMakeupList(); +// //loadKolStyleList(); +//}); +function loadMediaList() { + var formData = { + option_uid: 'media' + } + + $.ajax({ + url: "/AuthApi/optionItemList", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.optionItems; + var items = ""; + $.each(obj, function (index, item) { + items += optionItemHtml(item); + }); + + //items = '
    ' + items + '
'; + + $('#nestable05').children().html(items); + + $('#nestable05').nestable(); + + $('#nestable05').on('change', function () { + nestableChange(this); + }); + + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); +} +function loadCooperateTypeList() { + var formData = { + option_uid: 'cooperateType' + } + + $.ajax({ + url: "/AuthApi/optionItemList", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.optionItems; + var items = ""; + $.each(obj, function (index, item) { + items += optionItemHtml(item); + }); + + //items = '
    ' + items + '
'; + + $('#nestable04').children().html(items); + + $('#nestable04').nestable(); + + $('#nestable04').on('change', function () { + nestableChange(this); + }); + + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); +} +function loadFansTypeList() { + var formData = { + option_uid: 'fansType' + } + + $.ajax({ + url: "/AuthApi/optionItemList", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.optionItems; + var items = ""; + $.each(obj, function (index, item) { + items += optionItemHtml(item); + }); + + //items = '
    ' + items + '
'; + + $('#nestable03').children().html(items); + + $('#nestable03').nestable(); + + $('#nestable03').on('change', function () { + nestableChange(this); + }); + + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); +} +function loadKolStyleList() { + var formData = { + option_uid: 'kolStyle' + } + + $.ajax({ + url: "/AuthApi/optionItemList", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.optionItems; + var items = ""; + $.each(obj, function (index, item) { + items += optionItemHtml(item); + }); + + //items = '
    ' + items + '
'; + + $('#nestable02').children().html(items); + + $('#nestable02').nestable(); + + $('#nestable02').on('change', function () { + nestableChange(this); + }); + + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); +} +function nestableChange(obj) { + alert($(obj).attr("data-type")); + alert(window.JSON.stringify($(obj).nestable('serialize'))); +} +function loadKolMakeupList() { + var formData = { + option_uid: 'kolMakeup' + } + + $.ajax({ + url: "/AuthApi/optionItemList", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.optionItems; + var items = ""; + $.each(obj, function (index, item) { + items += optionItemHtml(item); + }); + + //items = '
    ' + items + '
'; + + $('#nestable01').children().html(items); + + $('#nestable01').nestable(); + + $('#nestable01').on('change', function () { + nestableChange(this); + }); + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); +} + +function optionItemHtml(item) { + var html = "
  • \n
    \n \n
    ").concat(item.optionItem_name, "
    \n
    \n \n \n
    \n
  • "); + return html; +} + +function editBtnClick(obj) { + + var optionItem_name = $(obj).parent().parent().find("[data-name='option_name']").text(); + var option_name = $(obj).parent().parent().parent().parent().parent().parent().find('.card-header.border-bottom-0').text(); + + $('#method').val('edit'); + $('#option_name').val(); + $('#option_uid').val($(obj).attr("data-parent-type")); + $('#optionItem_uid').val($(obj).attr("data-uid")); + $('#optionItemModal').modal('toggle'); + + + + $('#optionItem_name').val(optionItem_name).trigger("change"); + + $('#optionItemModal').modal('toggle'); +} + +function delBtnClick(obj) { + alert($(obj).attr("data-parent-uid")); +} + +function addItem(obj) { + //alert($(obj).attr("data-type")); + + $('#option_name').val($(obj).parent().parent().find('.card-header.border-bottom-0').text()); + $('#method').val('add'); + $('#option_uid').val($(obj).attr("data-type")); + $('#optionItemModal').modal('toggle'); + + tmpNestableObj = $(obj).parent().parent().find('.dd'); +} \ No newline at end of file