diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index 2368d4d..4bb35f6 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -59,6 +59,42 @@ namespace Journeys_WantHome.Controllers this._httpContextAccessor = httpContextAccessor; } + [Route("youtubeData")] + public ActionResult YoutubeData(IFormCollection obj) { + youtubeDataResult ret = new youtubeDataResult(); + 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"); + } + + string youtube_uid = obj["youtube_uid"].ToString(); + + if (youtube_uid == "") { + ret.ret = "no"; + ret.err_code = "00001"; + ret.message = "無 youtube_uid !"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + youtube objData = conn.QueryFirstOrDefault("select * from youtube where youtube_revoke = 'N' and youtube_uid = @youtube_uid", new { youtube_uid = youtube_uid }); + + if (objData == null) { + ret.ret = "no"; + ret.err_code = "00002"; + ret.message = "無此 youtube_uid 資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + ret.data = new youtubeDetailClass(objData); + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + [Route("youtubeList")] public ActionResult YoutubeList(IFormCollection obj) { youtubeListResult ret = new youtubeListResult(); @@ -1927,7 +1963,13 @@ namespace Journeys_WantHome.Controllers } - + public class youtubeDataResult + { + public string ret { get; set; } = "no"; + public string err_code { get; set; } = "0000"; + public string message { get; set; } = ""; + public youtubeDetailClass data = new youtubeDetailClass(); + } public class youtubeListResult { public string ret { get; set; } = "no"; diff --git a/Models/youtubeDetailClass.cs b/Models/youtubeDetailClass.cs index 01760ac..a5db439 100644 --- a/Models/youtubeDetailClass.cs +++ b/Models/youtubeDetailClass.cs @@ -10,7 +10,7 @@ public class youtubeDetailClass : youtube DbConn dbConn = new DbConn(); SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString")); - List youtubeDetails = new List(); + public List youtubeDetails = new List(); private youtube _youtube; public youtubeDetailClass() diff --git a/Views/Home/Dashboard.cshtml b/Views/Home/Dashboard.cshtml index 1266a6b..cebb543 100644 --- a/Views/Home/Dashboard.cshtml +++ b/Views/Home/Dashboard.cshtml @@ -48,3 +48,36 @@ + + +
+ +
\ No newline at end of file diff --git a/wwwroot/assets/javascript/custom/dashboard.js b/wwwroot/assets/javascript/custom/dashboard.js index 7ed946a..019eda1 100644 --- a/wwwroot/assets/javascript/custom/dashboard.js +++ b/wwwroot/assets/javascript/custom/dashboard.js @@ -98,4 +98,127 @@ function youtubeSubHtml(item) { html += " "; return html; +} + + +function youtubeBtnClick(obj) { + var dataUid = obj.getAttribute('data-uid'); + + + var trList = $("#youtube_layout").find(".masonry-item"); + $.each(trList, function (index, item) { + $(item).remove(); + }); + + var formData = { + youtube_uid: dataUid + } + + $.ajax({ + url: "/Api/youtubeData", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.data; + + var html = ""; + + $.each(obj.youtubeDetails, function (index, item) { + html += youtubeModalHtml(item); + }); + + $('#youtube_layout').append(html); + + $('#YoutubeModal').modal('toggle'); + + + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); +} + +function youtubeModalHtml(obj) { + + var publishdate = new Date(obj.youtubeDetail_publishedAt); + + var html = ""; + html += ""; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += " "; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += "
"; + html += " " + obj.youtubeDetail_title + ""; + html += "
"; + html += "
" + formatDate(publishdate, 'yyyy-MM-dd HH:mm:ss') + "
"; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += "
" + AppendComma(obj.youtubeDetail_viewCount) + "
"; + html += "

觀看數

"; + html += "
"; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += "
" + AppendComma(obj.youtubeDetail_likeCount) + "
"; + html += "

按讚數

"; + html += "
"; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += "
" + AppendComma(obj.youtubeDetail_commentCount) + "
"; + html += "

留言數

"; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + + return html; +} + +function formatDate(inputDate, format) { + if (!inputDate) return ''; + + const padZero = (value) => (value < 10 ? `0${value}` : `${value}`); + const parts = { + yyyy: inputDate.getFullYear(), + MM: padZero(inputDate.getMonth() + 1), + dd: padZero(inputDate.getDate()), + HH: padZero(inputDate.getHours()), + hh: padZero(inputDate.getHours() > 12 ? inputDate.getHours() - 12 : inputDate.getHours()), + mm: padZero(inputDate.getMinutes()), + ss: padZero(inputDate.getSeconds()), + tt: inputDate.getHours() < 12 ? 'AM' : 'PM' + }; + + return format.replace(/yyyy|MM|dd|HH|hh|mm|ss|tt/g, (match) => parts[match]); } \ No newline at end of file