AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"message_drawer_view_overview.min.js","sources":["../src/message_drawer_view_overview.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Controls the overview page of the message drawer.\n *\n * @module core_message/message_drawer_view_overview\n * @copyright 2018 Ryan Wyllie <ryan@moodle.com>\n * @license http://
www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n[\n 'jquery',\n 'core/key_codes',\n 'core/pubsub',\n 'core/str',\n 'core_message/message_drawer_router',\n 'core_message/message_drawer_routes',\n 'core_message/message_drawer_events',\n 'core_message/message_drawer_view_overview_section',\n 'core_message/message_repository',\n 'core_message/message_drawer_view_conversation_constants'\n],\nfunction(\n $,\n KeyCodes,\n PubSub,\n Str,\n Router,\n Routes,\n MessageDrawerEvents,\n Section,\n MessageRepository,\n Constants\n) {\n\n var SELECTORS = {\n CONTACT_REQUEST_COUNT: '[data-region=\"contact-request-count\"]',\n FAVOURITES: '[data-region=\"view-overview-favourites\"]',\n GROUP_MESSAGES: '[data-region=\"view-overview-group-messages\"]',\n MESSAGES: '[data-region=\"view-overview-messages\"]',\n SEARCH_INPUT: '[data-region=\"view-overview-search-input\"]',\n SECTION_TOGGLE_BUTTON: '[data-toggl
e]'\n };\n\n // Categories displayed in the message drawer. Some methods (such as filterCountsByType) are expecting their value\n // will be the same as the defined in the CONVERSATION_TYPES, except for the favourite.\n var OVERVIEW_SECTION_TYPES = {\n PRIVATE: [Constants.CONVERSATION_TYPES.PRIVATE, Constants.CONVERSATION_TYPES.SELF],\n PUBLIC: [Constants.CONVERSATION_TYPES.PUBLIC],\n FAVOURITE: null\n };\n\n var loadAllCountsPromise = null;\n\n /**\n * Load the total and unread conversation counts from the server for this user. This function\n * returns a jQuery promise that will be resolved with the counts.\n *\n * The request is only sent once per page load and will be cached for subsequent\n * calls to this function.\n *\n * @param {Number} loggedInUserId The logged in user's id\n * @return {Object} jQuery promise\n */\n var loadAllCounts = function(loggedInUserId) {\n if (loadAllCountsPromise === null) {\n
loadAllCountsPromise = MessageRepository.getAllConversationCounts(loggedInUserId);\n }\n\n return loadAllCountsPromise;\n };\n\n /**\n * Filter a set of counts to return only the count for the given type.\n *\n * This is used on the result returned by the loadAllCounts function.\n *\n * @param {Object} counts Conversation counts indexed by conversation type.\n * @param {Array|null} types The conversation types handlded by this section (null for all conversation types).\n * @param {bool} includeFavourites If this section includes favourites\n * @return {Number}\n */\n var filterCountsByTypes = function(counts, types, includeFavourites) {\n var total = 0;\n\n if (types && types.length) {\n total = types.reduce(function(carry, type) {\n return carry + counts.types[type];\n }, total);\n }\n\n if (includeFavourites) {\n total += counts.favourites;\n }\n\n return tot
al;\n };\n\n /**\n * Opens one of the sections based on whether the section has unread conversations\n * or any conversations\n *\n * Default section priority is favourites, groups, then messages. A section can increase\n * in priority if it has conversations in it. It can increase even further if it has\n * unread conversations.\n *\n * @param {Array} sections List of section roots, total counts, and unread counts.\n */\n var openSection = function(sections) {\n var isAlreadyOpen = sections.some(function(section) {\n var sectionRoot = section[0];\n return Section.isVisible(sectionRoot);\n });\n\n if (isAlreadyOpen) {\n // The user has already opened a section so there is nothing to do.\n return;\n }\n\n // Order the sections so that sections with unread conversations are prioritised\n // over sections without and sections with total conversations are prioritised\n // over
sections without.\n sections.sort(function(a, b) {\n var aTotal = a[1];\n var aUnread = a[2];\n var bTotal = b[1];\n var bUnread = b[2];\n\n if (aUnread > 0 && bUnread == 0) {\n return -1;\n } else if (aUnread == 0 && bUnread > 0) {\n return 1;\n } else if (aTotal > 0 && bTotal == 0) {\n return -1;\n } else if (aTotal == 0 && bTotal > 0) {\n return 1;\n } else {\n return 0;\n }\n });\n\n // Get the root of the first section after sorting.\n var sectionRoot = sections[0][0];\n var button = sectionRoot.find(SELECTORS.SECTION_TOGGLE_BUTTON);\n // Click it to expand it.\n button.click();\n };\n\n /**\n * Get the search input text element.\n *\n * @param {Object} header Overview header container element.\n * @return {Object} The search input element.\n */\
n var getSearchInput = function(header) {\n return header.find(SELECTORS.SEARCH_INPUT);\n };\n\n /**\n * Get the logged in user id.\n *\n * @param {Object} body Overview body container element.\n * @return {String} Logged in user id.\n */\n var getLoggedInUserId = function(body) {\n return body.attr('data-user-id');\n };\n\n /**\n * Decrement the contact request count. If the count is zero or below then\n * hide the count.\n *\n * @param {Object} header Conversation header container element.\n * @return {Function} A function to handle decrementing the count.\n */\n var decrementContactRequestCount = function(header) {\n return function() {\n var countContainer = header.find(SELECTORS.CONTACT_REQUEST_COUNT);\n var count = parseInt(countContainer.text(), 10);\n count = isNaN(count) ? 0 : count - 1;\n\n if (count <= 0) {\n countContainer.addClass('hidden');\n
} else {\n countContainer.text(count);\n }\n };\n };\n\n /**\n * Listen to, and handle event in the overview header.\n *\n * @param {String} namespace Unique identifier for the Routes\n * @param {Object} header Conversation header container element.\n */\n var registerEventListeners = function(namespace, header) {\n var searchInput = getSearchInput(header);\n var ignoredKeys = [KeyCodes.tab, KeyCodes.shift, KeyCodes.ctrl, KeyCodes.alt];\n\n searchInput.on('click', function() {\n Router.go(namespace, Routes.VIEW_SEARCH);\n });\n searchInput.on('keydown', function(e) {\n if (ignoredKeys.indexOf(e.keyCode) < 0 && e.key != 'Meta') {\n Router.go(namespace, Routes.VIEW_SEARCH);\n }\n });\n\n PubSub.subscribe(MessageDrawerEvents.CONTACT_REQUEST_ACCEPTED, decrementContactRequestCount(header));\n PubSub.subscribe(MessageDrawerEvents.CONTACT_REQUEST_DEC
LINED, decrementContactRequestCount(header));\n };\n\n /**\n * Setup the overview page.\n *\n * @param {String} namespace Unique identifier for the Routes\n * @param {Object} header Overview header container element.\n * @param {Object} body Overview body container element.\n * @return {Object} jQuery promise\n */\n var show = function(namespace, header, body) {\n if (!header.attr('data-init')) {\n registerEventListeners(namespace, header);\n header.attr('data-init', true);\n }\n var fromPanel = header.attr('data-in-panel') ? 'frompanel' : null;\n\n getSearchInput(header).val('');\n var loggedInUserId = getLoggedInUserId(body);\n var allCounts = loadAllCounts(loggedInUserId);\n\n var sections = [\n // Favourite conversations section.\n [body.find(SELECTORS.FAVOURITES), OVERVIEW_SECTION_TYPES.FAVOURITE, true],\n // Group conversations section.\n [body.find(SEL
ECTORS.GROUP_MESSAGES), OVERVIEW_SECTION_TYPES.PUBLIC, false],\n // Private conversations section.\n [body.find(SELECTORS.MESSAGES), OVERVIEW_SECTION_TYPES.PRIVATE, false]\n ];\n\n sections.forEach(function(args) {\n var sectionRoot = args[0];\n var sectionTypes = args[1];\n var includeFavourites = args[2];\n var totalCountPromise = allCounts.then(function(result) {\n return filterCountsByTypes(result.total, sectionTypes, includeFavourites);\n });\n var unreadCountPromise = allCounts.then(function(result) {\n return filterCountsByTypes(result.unread, sectionTypes, includeFavourites);\n });\n\n Section.show(namespace, null, sectionRoot, null, sectionTypes, includeFavourites,\n totalCountPromise, unreadCountPromise, fromPanel);\n });\n\n return allCounts.then(function(result) {\n var sectionParams = sections.map(fun
ction(section) {\n var sectionRoot = section[0];\n var sectionTypes = section[1];\n var includeFavourites = section[2];\n var totalCount = filterCountsByTypes(result.total, sectionTypes, includeFavourites);\n var unreadCount = filterCountsByTypes(result.unread, sectionTypes, includeFavourites);\n\n return [sectionRoot, totalCount, unreadCount];\n });\n\n // Open up one of the sections for the user.\n return openSection(sectionParams);\n });\n };\n\n /**\n * String describing this page used for aria-labels.\n *\n * @return {Object} jQuery promise\n */\n var description = function() {\n return Str.get_string('messagedrawerviewoverview', 'core_message');\n };\n\n return {\n show: show,\n description: description\n };\n});\n"],"names":["define","$","KeyCodes","PubSub","Str","Router","Routes"
,"MessageDrawerEvents","Section","MessageRepository","Constants","SELECTORS","OVERVIEW_SECTION_TYPES","PRIVATE","CONVERSATION_TYPES","SELF","PUBLIC","FAVOURITE","loadAllCountsPromise","filterCountsByTypes","counts","types","includeFavourites","total","length","reduce","carry","type","favourites","getSearchInput","header","find","decrementContactRequestCount","countContainer","count","parseInt","text","isNaN","addClass","show","namespace","body","attr","searchInput","ignoredKeys","tab","shift","ctrl","alt","on","go","VIEW_SEARCH","e","indexOf","keyCode","key","subscribe","CONTACT_REQUEST_ACCEPTED","CONTACT_REQUEST_DECLINED","registerEventListeners","fromPanel","val","loggedInUserId","getLoggedInUserId","allCounts","getAllConversationCounts","loadAllCounts","sections","forEach","args","sectionRoot","sectionTypes","totalCountPromise","then","result","unreadCountPromise","unread","some","section","isVisible","sort","a","b","aTotal","aUnread","bTotal","bUnread","click","openSection","map","description","get_strin
g"],"mappings":";;;;;;;AAsBAA,mDACA,CACI,SACA,iBACA,cACA,WACA,qCACA,qCACA,qCACA,oDACA,kCACA,4DAEJ,SACIC,EACAC,SACAC,OACAC,IACAC,OACAC,OACAC,oBACAC,QACAC,kBACAC,eAGIC,gCACuB,wCADvBA,qBAEY,2CAFZA,yBAGgB,+CAHhBA,mBAIU,yCAJVA,uBAKc,6CALdA,gCAMuB,gBAKvBC,uBAAyB,CACzBC,QAAS,CAACH,UAAUI,mBAAmBD,QAASH,UAAUI,mBAAmBC,MAC7EC,OAAQ,CAACN,UAAUI,mBAAmBE,QACtCC,UAAW,MAGXC,qBAAuB,KA8BvBC,oBAAsB,SAASC,OAAQC,MAAOC,uBAC1CC,MAAQ,SAERF,OAASA,MAAMG,SACfD,MAAQF,MAAMI,QAAO,SAASC,MAAOC,aAC1BD,MAAQN,OAAOC,MAAMM,QAC7BJ,QAGHD,oBACAC,OAASH,OAAOQ,YAGbL,OA2DPM,eAAiB,SAASC,eACnBA,OAAOC,KAAKpB,yBAoBnBqB,6BAA+B,SAASF,eACjC,eACCG,e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