return (data) => { if (ttl) { console.log('Ajax::cacheResponse# Caching response with key:', key, 'for', ttl, 'minutes.'); lscache.set(data.url, data.result, ttl); // Last parameter is TTL in minutes } return data.result; };
render: function(){ // render the todos lscache.set('todos', todos); var todoHtml = _.map(todos, function(todo){ // = _.map(todos, function(todo) replaces = todos(function(todo) return template(todo); // a function we pass another function into }); // get an array as the result i.e. return ==>same as this: var iterator = function (todo){return template(todo);}; ==> iterating through an array for each ul in the template; each iteration/item in the list creates HTML, which is stored as todoHtml app.unbindEvents(); $('ul.list-group').html(todoHtml.join('')); app.bindEvents(); },
render: function(){ // render the todos lscache.set('todos', todos); var todoHtml = todos.map(function(todo){ return template(todo); }); app.unbindEvents(); $('.list-group').html(todoHtml.join('')); app.bindEvents(); },
render: function(){ // render the todos lscache.set('savedTodos', todos); var todoHtml = _.map(todos, function(toDo){ return template(toDo); // the return value ends up being HTML code }); app.unbindEvents(); $('ul.list-group').html(todoHtml.join('')); app.bindEvents(); },
render: function() { lscache.set('todos', todos); // Create an array of HTML strings var todoHtml = _.map(todos, function(todo){ // The function template returns HTML code // with our data interpolated into the HTML. return template(todo); }); app.unbindEvents(); // .join converts the array of strings into one string // .html adds the HTML string to our <ul> $('ul.list-group').html(todoHtml.join('')); app.bindEvents(); },
render: function() { // render the todos /* var iterator = function(todo){ return template(todo;) }, */ // go through the array return the template into html lscache.set('todos', todos); var todohtml = _.map(todos, function(todo){ return template(todo); }); /* var todoHtml = todos.map(iterator;) */ app.unbindEvents(); $('ul.list-group').html(todohtml.join('')); // fill the DOM app.bindEvents(); },
co(function* () { let data = yield api.jql(query); if (!data || !data.issues) { return; } let allProcessedData = _.merge(acc, processIssues(data.issues), {}); if (data.total > (data.maxResults + data.startAt)) { if (!cache.get('linkedTickets')) { renderTickets(allProcessedData); filter.filter(true); } return getTickets(project, data.maxResults + data.startAt, allProcessedData); } renderTickets(allProcessedData); filter.filter(true); cache.set('linkedTickets:' + project, allProcessedData); //console.log('Jira Improved: all tickets complete for ' + project, allProcessedData); }).catch(function(err) { console.error(err.message, err); });
save: function(){ // debugger; var data = this.get('todos'); data = this.applySchema(data); lscache.set('todos', data); },
save: function(){ var data = this.get('todos'); data = this.applySchema(data); lscache.set('todos', data); // saves the data },
return fetch(url).then(r => r.json()).then(r => { lscache.set(url, r, timeout); return r; });
export const setUserInfoToCache = (userInfo) => { lscache.set(USER_INFO, JSON.stringify(userInfo)) lscache.set(LOGIN_TIME, Date.now()) lscache.set(TOKEN, userInfo[TOKEN]) }
export default (() => { const TOKEN = config.accessToken || 'token' const LOGIN_TIME = 'UserLoginTime' const USER_INFO = 'UserInfo' return { /** * 空对象判断 * @param obj * @returns {boolean} */ isEmpty (obj) { for (var key in obj) return false return true }, isUrl(path) { /* eslint no-useless-escape:0 */ const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/; return reg.test(path); }, urlToList(url) { const urllist = url.split('/').filter(i => i); return urllist.map((urlItem, index) => `/${urllist.slice(0, index + 1).join('/')}`); }, /** * 获取登录剩余时间秒数 * @returns {number} */ getLoginRemainingTime () { const loginTime = Math.ceil(+lscache.get(LOGIN_TIME) / 1000) return (config.sessionDuration || 30 * 60 * 1000) / 1000 - (Math.ceil(Date.now() / 1000) - loginTime) }, /** * 从缓存获取用户信息 */ getUserInfoFromCache () { return JSON.parse(lscache.get(USER_INFO) || '""') }, getAccessToken () { return lscache.get(TOKEN) }, /** * 保存用户信息到缓存 * @param userInfo */ setUserInfoToCache (userInfo) { lscache.set(USER_INFO, JSON.stringify(userInfo)) lscache.set(LOGIN_TIME, Date.now()) lscache.set(TOKEN, userInfo[TOKEN]) }, /** * 移除缓存中的用户信息 */ removeUserInfoFromCache () { lscache.remove(USER_INFO) lscache.remove(LOGIN_TIME) lscache.remove(TOKEN) }, /** * 参数对象转换成请求参数字符串 * @param params * @returns {*} */ params2query (params) { if (typeof params !== 'object') return '' var queries = [] for (var i in params) { if (params.hasOwnProperty(i)) { params[i] && queries.push(i + '=' + params[i]) } } return queries.join('&') }, query2params (query) { if (typeof query !== 'string') return {} let param = {}; let params = query.split('&'); for (let i = 0, len = params.length; i < len; i++) { if (!params[i]) continue; const kv = params[i].split('='); if (kv[0] && kv[1]) param[kv[0]] = kv[1]; } return param }, /** * uuid */ uuid () { let s = [] const hexDigits = '0123456789abcdef' for (let i = 0; i < 36; i++) { s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1) } s[14] = '4' s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1) s[8] = s[13] = s[18] = s[23] = '-' return s.join('') } } })()
.then((data) => { lscache.set(url, data, CACHE_EXPIRY) return data })
function runExtension() { console.log('(((============ JIRA IMPROVED ' + manifest.version + ' ADDED ==============)))'); const cache = require('lscache'); const CACHE_VERSION = 3; if (cache.get('CACHE_VERSION') !== CACHE_VERSION) { console.log('Jira Improved', 'Old cache version:', cache.get('CACHE_VERSION'), 'flushing to use', CACHE_VERSION); cache.flush(); cache.set('CACHE_VERSION', CACHE_VERSION); } const epicTickets = require('./tickets/epic-tickets'); const issueTickets = require('./tickets/issue-tickets'); const filter = require('./ui/filter'); const avatar = require('./ui/avatar'); const customFields = require('./customfields'); const co = require('co'); function init () { co(function* () { console.log('Jira Improved: Calling Init'); avatar.update(); // make sure this is using the same data let data = yield GH.WorkDataLoader.getData(page.rapidViewID); yield customFields.init(); let rapidViewId = data.rapidViewId; cache.setBucket('improved:' + rapidViewId); epicTickets.decorate(data); issueTickets.decorate(data); // must re-register in case of updates page.changed(init); }); } function update () { console.log('Jira Improved: Calling Update'); avatar.update(); epicTickets.update(); issueTickets.update(); page.changed(init); } if (GH && GH.SwimlaneView && GH.SwimlaneView.rerenderCellOfIssue) { var original = {}; original['GH.SwimlaneView.rerenderCellOfIssue'] = GH.SwimlaneView.rerenderCellOfIssue; GH.SwimlaneView.rerenderCellOfIssue = function(key) { console.log('issue updated:', key); original['GH.SwimlaneView.rerenderCellOfIssue'](key); update(); }; } avatar.update(); filter.init(); page.changed(init); }