'use strict'; angular.module('PromptSkill.filters', []) .filter('title', [function() { // return function(page) { // //console.log($('title').text()) var title = "PROMPT SKILL's E-Learning Platform"; // if (page != undefined) { if (page.length > 0) { title = page + " : " + title; } } // return title; } }]) .filter('viewport', ['ngMeta', function(ngMeta) { // return function(device) { // var viewport = 'width=device-width, initial-scale=1.0'; if (!_.isUndefined(device)) { var devices = device.replace(/[\s,]+/g, ',').split(","); // console.log(devices); function responsiveDevice() { if (!devices.includes('mobile') && screen.width <= 600) { viewport = 'width=1440'; } if (!devices.includes('tablet') && (screen.width > 600 && screen.width <= 1024)) { viewport = 'width=1920'; } // window.addEventListener("resize", function () { // if (window.innerWidth > window.innerHeight) { // viewport = 'width=1440'; // ngMeta.setTag('device', 'width=1440'); // alert(viewport); // } else { // viewport = 'width=device-width, initial-scale=1.0'; // } // }); // if (window.matchMedia("(orientation: landscape)").matches && screen.width <= 1024) { // viewport = 'width=1440'; // } else { // } } responsiveDevice(); } // return viewport; } }]) .filter('coursename', ['$sanitize', function($sanitize) { // var tag = (/xhtml/i).test(document.doctype) ? '
' : '
'; return function(text) { // ngSanitize's linky filter changes \r and \n to and respectively text = (text + '').replace(/(\r\n|\n\r|\r|\n| | | | )/g, tag + '$1'); // text = text.split(tag); //console.log(text) if (text[1] != undefined) { text[1] = '' + text[1] + ''; } return $sanitize(text.join('')); } }]) // .filter('price', function() { // // // return function(price) { // // // if (parseInt(price) >0) // return price + ' บาท'; // } // }) .filter('textdate', [function() { // return function(date) { // if (date) { var strDate = ''; var yearAdj = 543; //console.log(date) var months = ['ม.ค.', 'ก.พ.', 'มี.ค.', 'เม.ย.', 'พ.ค.', 'มิ.ย.', 'ก.ค.', 'ส.ค.', 'ก.ย.', 'ต.ค.', 'พ.ย.', 'ธ.ค.']; if (typeof date === 'string') { // var t = date.split(/[- :]/); // date = new Date(t[0], t[1] - 1, t[2], t[3] || 0, t[4] || 0, t[5] || 0); } else { date = new Date(date * 1000); } return date.getDate() + " " + months[date.getMonth()] + " " + (date.getFullYear() + yearAdj) } return ''; } }]) .filter('time', [function() { // return function(text) { if (text != undefined && text.length > 0) return text.replace(/[\s]/g, '') + ' น.'; return ''; } }]) .filter('minute', [function() { // return function(time) { // var min = Math.floor(time / 60); if (min > 0) return min + ' นาที'; return ''; } }]) .filter('score', [function() { // return function(item) { //console.log(item) if (item.scored == undefined) { item.scored = '-'; } return (item.score > 0) ? '(คะแนน ' + item.scored + '/' + item.score + ')' : '(ไม่มีคะแนน)'; } }]) .filter('progress', [function() { // return function(progress) { // var text = 'จากการเรียน ' + progress + '%
คะแนนเต็ม 100%'; return text; } }]) .filter('unsafe', ['$sce', function($sce) { return function(htmlText) { return $sce.trustAsHtml(htmlText); } }]) .filter('privilege', [function() { // return function(privilege) { // return privilege; } }]) .filter('thaidate', [function() { // return function(date) { // var strDate = ''; var yearAdj = 543; var months = ['ม.ค.', 'ก.พ.', 'มี.ค.', 'เม.ย.', 'พ.ค.', 'มิ.ย.', 'ก.ค.', 'ส.ค.', 'ก.ย.', 'ต.ค.', 'พ.ย.', 'ธ.ค.']; //months = ['ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.']; if (typeof date === 'string') { var t = date.split(/[- :]/); date = new Date(t[0], t[1] - 1, t[2], t[3] || 0, t[4] || 0, t[5] || 0); } else { date = date * 1000; } strDate = date.getDate() + " " + months[date.getMonth()] + " " + (date.getFullYear() + yearAdj) return strDate; } }]) .filter('date_format_th', [function() { // return function(strDate) { if (strDate) { var date = new Date(strDate * 1000); var months = ['มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม', 'มิถุนายน', 'กรกฎาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน', 'ธันวาคม']; var yearAdj = 543; // var day = date.getDate(); // var day = (date.getDate() < 10 ? '0' : '') + date.getDate(); var month = months[date.getMonth()]; var year = date.getFullYear() + yearAdj; // strDate = day + " " + month + " " + year; } return strDate; } }]) .filter('nl2br', ['$sanitize', function($sanitize) { var tag = (/xhtml/i).test(document.doctype) ? '
' : '
'; // return function(msg) { // ngSanitize's linky filter changes \r and \n to and respectively msg = (msg + '').replace(/(\r\n|\n\r|\r|\n| | | | )/g, tag + '$1'); return $sanitize(msg); }; }]) .filter('trustAsHtml', ['$sce', function($sce) { // return function(text) { return $sce.trustAsHtml(text); }; }]) .filter('trustAsResourceUrl', ['$sce', function($sce) { // return function(val) { return $sce.trustAsResourceUrl(val); }; }]) .filter('numberRoundUp', [function() { // return function(val) { return Math.ceil(val); }; }]) .filter('isEmpty', [function() { // return function(object) { if (object) { return Object.keys(object).length > 0; } }; }]) .filter('time', ['$filter', function($filter) { // return function(minute, locale) { let time_str = '-'; minute = parseInt(minute); if (minute) { const hours = Math.floor(minute / 60); const minutes = minute % 60; if (hours > 0) { time_str = minutes > 0 ? `${hours} ${$filter('phrase')('Hour', locale)} ${minutes} ${$filter('phrase')('Minutes', locale)}` : `${hours} ${$filter('phrase')('Hour', locale)}`; } else { time_str = minutes > 0 ? `${minutes} ${$filter('phrase')('Minutes', locale)}` : '-'; } } return time_str; }; }]) .filter('toLocaleString', [function() { // return function(num) { if (num != undefined) { return parseInt(num).toLocaleString(); } }; }]) .filter('phrase', [function(locale) { // return function(text, locale) { // console.log(text) if (text) { if (locale) { return locale[text]; } return text; } }; }]) .filter('locale', [function() { // return function(locale) { // let language = ''; switch (locale) { case 'en-US': language = 'EN'; break; default: language = 'TH'; } return language; }; }]) .filter('refno', [function() { // return function(order) { // return order + String(Math.floor(Math.random() * 100)).padStart(2, 0); }; }]) .filter('currency', [function() { // return function(unit, payment) { // if (payment == 'paysolution') { switch (unit) { case 'USD': unit = '01'; break; default: unit = '00'; } } return unit; }; }]) .filter('price', [function() { // return function(price, unit) { // console.log(unit) if (price) { const options = { minimumFractionDigits: 2, maximumFractionDigits: 2 }; price = parseFloat(price).toLocaleString(undefined, options); switch (unit) { case 'USD': price = `US$${price}`; break; case 'Baht': price = `${price} บาท`; break; default: price = '-'; } } return price; }; }]) .filter('truncateDecimal2', [function() { // return function(input) { if (isNaN(input)) return input; return Math.floor(parseFloat(input) * 100) / 100; }; }]) // .filter('wordcut', [function() { // // // return function(text) { // // // if(text) { // var wordcut = require("wordcut"); // wordcut.init(); // console.log(text); // return wordcut.cut(text); // } // }; // }]) ;