Best JavaScript code snippet using devicefarmer-stf
groups-controller.js
Source:groups-controller.js
...63 $scope.groupsEnv[group.id].availableDevices.forEach(function(device) {64 publishDevice(device)65 })66 }67 function getAvailableGroupDevices(group) {68 if (group.class === 'bookable') {69 initAvailableGroupDevices(group, originDevices, originDevicesBySerial)70 }71 else if (group.class === 'standard') {72 initAvailableGroupDevices(group, standardizableDevices, standardizableDevicesBySerial)73 }74 else if ($scope.groupsEnv[group.id].showDevices) {75 GroupsService.getGroupDevices(group.id, true, deviceFields).then(function(response) {76 if (CommonService.isExisting($scope.groupsEnv[group.id])) {77 $scope.groupsEnv[group.id].availableDevicesBySerial = {}78 $scope.groupsEnv[group.id].availableDevices = []79 response.data.devices.forEach(function(device) {80 addAvailableGroupDevice(group.id, device, -1)81 })82 initAvailableGroupDevices(83 group84 , $scope.groupsEnv[group.id].availableDevices85 , $scope.groupsEnv[group.id].availableDevicesBySerial)86 }87 })88 }89 }90 function checkDurationQuota(group, deviceNumber, startDate, stopDate, repetitions) {91 if (CommonService.isOriginGroup(group.class)) {92 return true93 }94 if (CommonService.isExisting($scope.usersByEmail[group.owner.email])) {95 const duration =96 (group.devices.length + deviceNumber) *97 ((new Date(stopDate)) - (new Date(startDate))) *98 (repetitions + 1)99 if (duration <=100 $scope.users[$scope.usersByEmail[group.owner.email].index]101 .groups.quotas.allocated.duration) {102 return true103 }104 }105 return false106 }107 function isBookedDevice(serial) {108 if (CommonService.isExisting(originDevicesBySerial[serial])) {109 for(var i in $scope.groups) {110 if (!CommonService.isOriginGroup($scope.groups[i].class) &&111 $scope.groups[i].devices.indexOf(serial) > -1) {112 return true113 }114 }115 }116 return false117 }118 function addStandardizableDevicesIfNotBooked(devices, timeStamp) {119 devices.forEach(function(serial) {120 if (!isBookedDevice(serial)) {121 addStandardizableDevice(122 originDevices[originDevicesBySerial[serial].index]123 , timeStamp124 )125 }126 })127 }128 function updateStandardizableDeviceIfNotBooked(device, timeStamp) {129 if (!isBookedDevice(device.serial)) {130 updateStandardizableDevice(device, timeStamp)131 }132 }133 function initGroup(group) {134 cachedGroupsClass[group.id] = group.class135 if (typeof $scope.groupsEnv[group.id] === 'undefined') {136 $scope.groupsEnv[group.id] = {}137 initAvailableGroupDevices(group, [], {})138 if (group.privilege === 'root') {139 rootGroupId = group.id140 }141 }142 return group143 }144 function addGroup(group, timeStamp) {145 if (CommonService.add($scope.groups, groupsById, group, 'id', timeStamp)) {146 return initGroup(group)147 }148 return null149 }150 function updateGroup(group, timeStamp, noAdding) {151 if (CommonService.update($scope.groups, groupsById, group, 'id', timeStamp, noAdding)) {152 return initGroup($scope.groups[groupsById[group.id].index])153 }154 return null155 }156 function deleteGroup(id, timeStamp) {157 const group = CommonService.delete($scope.groups, groupsById, id, timeStamp)158 if (group) {159 delete $scope.groupsEnv[group.id]160 }161 return group162 }163 function addOriginDevice(device, timeStamp) {164 return CommonService.add(originDevices, originDevicesBySerial, device, 'serial', timeStamp)165 }166 function updateOriginDevice(device, timeStamp) {167 return CommonService.update(originDevices, originDevicesBySerial, device, 'serial', timeStamp)168 }169 function deleteOriginDevice(serial, timeStamp) {170 return CommonService.delete(originDevices, originDevicesBySerial, serial, timeStamp)171 }172 function addStandardizableDevice(device, timeStamp) {173 return CommonService.add(174 standardizableDevices, standardizableDevicesBySerial, device, 'serial', timeStamp)175 }176 function updateStandardizableDevice(device, timeStamp) {177 return CommonService.update(178 standardizableDevices, standardizableDevicesBySerial, device, 'serial', timeStamp)179 }180 function deleteStandardizableDevice(serial, timeStamp) {181 return CommonService.delete(182 standardizableDevices, standardizableDevicesBySerial, serial, timeStamp)183 }184 function addAvailableGroupDevice(id, device, timeStamp) {185 return CommonService.add(186 $scope.groupsEnv[id].availableDevices187 , $scope.groupsEnv[id].availableDevicesBySerial, device, 'serial', timeStamp)188 }189 function updateAvailableGroupDevice(id, device, timeStamp, noAdding) {190 return CommonService.update(191 $scope.groupsEnv[id].availableDevices192 , $scope.groupsEnv[id].availableDevicesBySerial, device, 'serial', timeStamp, noAdding)193 }194 function deleteAvailableGroupDevice(id, serial, timeStamp) {195 return CommonService.delete(196 $scope.groupsEnv[id].availableDevices197 , $scope.groupsEnv[id].availableDevicesBySerial, serial, timeStamp)198 }199 function addUser(user, timeStamp) {200 return CommonService.add($scope.users, $scope.usersByEmail, user, 'email', timeStamp)201 }202 function updateUser(user, timeStamp) {203 return CommonService.update($scope.users, $scope.usersByEmail, user, 'email', timeStamp)204 }205 function deleteUser(email, timeStamp) {206 return CommonService.delete($scope.users, $scope.usersByEmail, email, timeStamp)207 }208 function initScope() {209 GroupsService.getOboeMyGroups(function(group) {210 addGroup(group, -1)211 })212 .done(function() {213 $scope.$digest()214 })215 UsersService.getOboeUsers(userFields, function(user) {216 addUser(user, -1)217 })218 .done(function() {219 if (CommonService.isExisting($scope.usersByEmail[$scope.currentUser.email])) {220 $scope.users[$scope.usersByEmail[$scope.currentUser.email].index] = $scope.currentUser221 }222 })223 UserService.getUser().then(function(response) {224 CommonService.merge($scope.currentUser, response.data.user)225 })226 if ($scope.isAdmin()) {227 DevicesService.getOboeDevices('origin', deviceFields, function(device) {228 addOriginDevice(device, -1)229 })230 DevicesService.getOboeDevices('standardizable', deviceFields, function(device) {231 addStandardizableDevice(device, -1)232 })233 }234 }235 $scope.currentUser = CommonService.merge({}, UserService.currentUser)236 $scope.users = []237 $scope.usersByEmail = {}238 $scope.groups = []239 $scope.groupsEnv = {}240 $scope.confirmRemove = {value: true}241 $scope.scopeGroupsCtrl = $scope242 $scope.itemsPerPageOptions = ItemsPerPageOptionsService243 SettingsService.bind($scope, {244 target: 'groupItemsPerPage'245 , source: 'groupItemsPerPage'246 , defaultValue: $scope.itemsPerPageOptions[2]247 })248 $scope.userColumns = [249 {name: 'Name', property: 'name'}250 , {name: 'Email', property: 'email'}251 , {name: 'Privilege', property: 'privilege'}252 ]253 $scope.defaultUserData = {254 columns: [255 {name: 'Name', sort: 'sort-asc'}256 , {name: 'Email', sort: 'none'}257 , {name: 'Privilege', sort: 'none'}258 ]259 , sort: {index: 0, reverse: false}260 }261 SettingsService.bind($scope, {262 target: 'userData'263 , source: 'userData'264 , defaultValue: $scope.defaultUserData265 })266 SettingsService.bind($scope, {267 target: 'groupUserData'268 , source: 'groupUserData'269 , defaultValue: $scope.defaultUserData270 })271 $scope.conflictColumns = [272 {name: 'Serial', property: 'serial'}273 , {name: 'Starting Date', property: 'startDate'}274 , {name: 'Expiration Date', property: 'stopDate'}275 , {name: 'Group Name', property: 'group'}276 , {name: 'Group Owner', property: 'ownerName'}277 ]278 $scope.defaultConflictData = {279 columns: [280 {name: 'Serial', sort: 'sort-asc'}281 , {name: 'Starting Date', sort: 'none'}282 , {name: 'Expiration Date', sort: 'none'}283 , {name: 'Group Name', sort: 'none'}284 , {name: 'Group Owner', sort: 'none'}285 ]286 , sort: {index: 0, reverse: false}287 }288 SettingsService.bind($scope, {289 target: 'conflictData'290 , source: 'conflictData'291 , defaultValue: $scope.defaultConflictData292 })293 $scope.mailToGroupOwners = function(groups) {294 CommonService.copyToClipboard(_.uniq(groups.map(function(group) {295 return group.owner.email296 }))297 .join(SettingsService.get('emailSeparator')))298 .url('mailto:?body=*** Paste the email addresses from the clipboard! ***')299 }300 $scope.mailToGroupUsers = function(group, users) {301 // group unused actually..302 $scope.mailToAvailableUsers(users)303 }304 $scope.mailToAvailableUsers = function(users) {305 CommonService.copyToClipboard(users.map(function(user) {306 return user.email307 })308 .join(SettingsService.get('emailSeparator')))309 .url('mailto:?body=*** Paste the email addresses from the clipboard! ***')310 }311 $scope.getGroupIndex = function(relativeIndex) {312 return relativeIndex + ($scope.groupCurrentPage - 1) * $scope.groupItemsPerPage.value313 }314 $scope.computeDisplay = function(device) {315 return device.display.width * device.display.height316 }317 $scope.computeNetwork = function(device) {318 if (!device.network || !device.network.type) {319 return ''320 }321 else if (device.network.subtype) {322 return device.network.type + ' (' + device.network.subtype + ')'323 }324 return device.network.type325 }326 $scope.resetDeviceData = function() {327 $scope.deviceData = JSON.parse(JSON.stringify($scope.defaultDeviceData))328 }329 $scope.resetGroupDeviceData = function() {330 $scope.groupDeviceData = JSON.parse(JSON.stringify($scope.defaultDeviceData))331 }332 $scope.deviceColumns = [333 {name: 'Model', property: 'model'}334 , {name: 'Serial', property: 'serial'}335 , {name: 'Carrier', property: 'operator'}336 , {name: 'OS', property: 'version'}337 , {name: 'Network', property: $scope.computeNetwork}338 , {name: 'Screen', property: $scope.computeDisplay}339 , {name: 'Manufacturer', property: 'manufacturer'}340 , {name: 'SDK', property: 'sdk'}341 , {name: 'ABI', property: 'abi'}342 , {name: 'CPU Platform', property: 'cpuPlatform'}343 , {name: 'OpenGL ES version', property: 'openGLESVersion'}344 , {name: 'Market name', property: 'marketName'}345 , {name: 'Phone IMEI', property: 'phone.imei'}346 , {name: 'Location', property: 'provider.name'}347 , {name: 'Group Origin', property: 'group.originName'}348 ]349 $scope.defaultDeviceData = {350 columns: [351 {name: 'Model', selected: true, sort: 'sort-asc'}352 , {name: 'Serial', selected: true, sort: 'none'}353 , {name: 'Carrier', selected: false, sort: 'none'}354 , {name: 'OS', selected: true, sort: 'none'}355 , {name: 'Network', selected: false, sort: 'none'}356 , {name: 'Screen', selected: true, sort: 'none'}357 , {name: 'Manufacturer', selected: true, sort: 'none'}358 , {name: 'SDK', selected: true, sort: 'none'}359 , {name: 'ABI', selected: false, sort: 'none'}360 , {name: 'CPU Platform', selected: false, sort: 'none'}361 , {name: 'OpenGL ES version', selected: false, sort: 'none'}362 , {name: 'Market name', selected: true, sort: 'none'}363 , {name: 'Phone IMEI', selected: false, sort: 'none'}364 , {name: 'Location', selected: true, sort: 'none'}365 , {name: 'Group Origin', selected: true, sort: 'none'}366 ]367 , sort: {index: 0, reverse: false}368 }369 SettingsService.bind($scope, {370 target: 'deviceData'371 , source: 'deviceData'372 , defaultValue: $scope.defaultDeviceData373 })374 SettingsService.bind($scope, {375 target: 'groupDeviceData'376 , source: 'groupDeviceData'377 , defaultValue: $scope.defaultDeviceData378 })379 $scope.nameRegex = /^[0-9a-zA-Z-_./: ]{1,50}$/380 $scope.nameRegexStr = '/^[0-9a-zA-Z-_./: ]{1,50}$/'381 $scope.classOptions = CommonService.classOptions382 $scope.getClassName = CommonService.getClassName383 $scope.sortBy = CommonService.sortBy384 $scope.isAdmin = function() {385 return $scope.currentUser.privilege === 'admin'386 }387 $scope.getRepetitionsQuotas = function(email) {388 if (CommonService.isExisting($scope.usersByEmail[email])) {389 return $scope.users[$scope.usersByEmail[email].index].groups.quotas.repetitions390 }391 return null392 }393 $scope.initShowDevices = function(group, showDevices) {394 if (typeof $scope.groupsEnv[group.id].groupDeviceCurrentPage === 'undefined') {395 $scope.groupsEnv[group.id].groupDeviceCurrentPage = 1396 $scope.groupsEnv[group.id].groupDeviceItemsPerPage = $scope.itemsPerPageOptions[1]397 $scope.groupsEnv[group.id].availableDeviceCurrentPage = 1398 $scope.groupsEnv[group.id].availableDeviceItemsPerPage = $scope.itemsPerPageOptions[1]399 }400 $scope.groupsEnv[group.id].showDevices = showDevices401 getAvailableGroupDevices(group)402 }403 $scope.initShowUsers = function(group) {404 if (typeof $scope.groupsEnv[group.id].groupUserCurrentPage === 'undefined') {405 $scope.groupsEnv[group.id].groupUserCurrentPage = 1406 $scope.groupsEnv[group.id].groupUserItemsPerPage = $scope.itemsPerPageOptions[1]407 $scope.groupsEnv[group.id].availableUserCurrentPage = 1408 $scope.groupsEnv[group.id].availableUserItemsPerPage = $scope.itemsPerPageOptions[1]409 }410 }411 $scope.watchGroupClass = function(group) {412 if (CommonService.isNoRepetitionsGroup($scope.groupsEnv[group.id].tmpClass)) {413 $scope.groupsEnv[group.id].tmpRepetitions = 0414 }415 else if ($scope.groupsEnv[group.id].tmpRepetitions === 0) {416 $scope.groupsEnv[group.id].tmpRepetitions = 1417 }418 }419 $scope.initTemporaryName = function(group) {420 $scope.groupsEnv[group.id].tmpName = group.name421 $scope.groupsEnv[group.id].tmpNameTooltip = 'No change'422 }423 $scope.initTemporarySchedule = function(group) {424 $scope.groupsEnv[group.id].tmpClass = group.class425 $scope.groupsEnv[group.id].tmpRepetitions = group.repetitions426 $scope.groupsEnv[group.id].tmpStartDate = new Date(group.dates[0].start)427 $scope.groupsEnv[group.id].tmpStopDate = new Date(group.dates[0].stop)428 $scope.groupsEnv[group.id].tmpScheduleTooltip = 'No change'429 }430 $scope.conditionForDevicesAddition = function(group, deviceNumber) {431 return checkDurationQuota(432 group433 , deviceNumber434 , group.dates[0].start435 , group.dates[0].stop436 , group.repetitions437 )438 }439 $scope.conditionForGroupCreation = function() {440 return $scope.currentUser.groups.quotas.consumed.number <441 $scope.currentUser.groups.quotas.allocated.number442 }443 $scope.conditionForGroupUsersRemoving = function(group, users) {444 return !(users.length === 0 ||445 group.privilege === 'root' && users.length === 1 && users[0].privilege === 'admin' ||446 group.privilege !== 'root' &&447 (users.length === 2 &&448 (users[0].privilege === 'admin' && users[1].email === group.owner.email ||449 users[0].email === group.owner.email && users[1].privilege === 'admin') ||450 users.length === 1 &&451 (users[0].email === group.owner.email || users[0].privilege === 'admin'))452 )453 }454 $scope.conditionForNameSaving = function(group, formInvalidStatus) {455 return !formInvalidStatus && $scope.groupsEnv[group.id].tmpName !== group.name456 }457 $scope.conditionForScheduleSaving = function(group, formInvalidStatus) {458 if (formInvalidStatus) {459 $scope.groupsEnv[group.id].tmpScheduleTooltip = 'Bad syntax'460 return false461 }462 if ($scope.groupsEnv[group.id].tmpClass !== group.class ||463 parseInt($scope.groupsEnv[group.id].tmpRepetitions, 10) !== group.repetitions ||464 $scope.groupsEnv[group.id].tmpStartDate.getTime() !==465 (new Date(group.dates[0].start)).getTime() ||466 $scope.groupsEnv[group.id].tmpStopDate.getTime() !==467 (new Date(group.dates[0].stop)).getTime()) {468 if (!CommonService.isNoRepetitionsGroup($scope.groupsEnv[group.id].tmpClass)) {469 if (parseInt($scope.groupsEnv[group.id].tmpRepetitions, 10) === 0) {470 $scope.groupsEnv[group.id].tmpScheduleTooltip = 'Repetitions must be > 0 for this Class'471 return false472 }473 }474 if ($scope.groupsEnv[group.id].tmpStartDate >= $scope.groupsEnv[group.id].tmpStopDate) {475 $scope.groupsEnv[group.id].tmpScheduleTooltip = 'Starting date >= Expiration date'476 return false477 }478 if (($scope.groupsEnv[group.id].tmpStopDate - $scope.groupsEnv[group.id].tmpStartDate) >479 CommonService.getClassDuration($scope.groupsEnv[group.id].tmpClass)) {480 $scope.groupsEnv[group.id].tmpScheduleTooltip =481 '(Expiration date - Starting date) must be <= Class duration'482 return false483 }484 if ($scope.isAdmin() &&485 group.devices.length &&486 (CommonService.isOriginGroup(group.class) &&487 !CommonService.isOriginGroup($scope.groupsEnv[group.id].tmpClass) ||488 CommonService.isOriginGroup($scope.groupsEnv[group.id].tmpClass) &&489 !CommonService.isOriginGroup(group.class))) {490 $scope.groupsEnv[group.id].tmpScheduleTooltip =491 'Unauthorized class while device list is not empty'492 return false493 }494 if (!checkDurationQuota(495 group496 , 0497 , $scope.groupsEnv[group.id].tmpStartDate498 , $scope.groupsEnv[group.id].tmpStopDate499 , $scope.groupsEnv[group.id].tmpRepetitions)) {500 $scope.groupsEnv[group.id].tmpScheduleTooltip = 'Group duration quotas is reached'501 return false502 }503 $scope.groupsEnv[group.id].tmpScheduleTooltip = ''504 return true505 }506 $scope.groupsEnv[group.id].tmpScheduleTooltip = 'No change'507 return false508 }509 $scope.conditionForRepetitions = function(group) {510 return !CommonService.isNoRepetitionsGroup($scope.groupsEnv[group.id].tmpClass)511 }512 $scope.addGroupDevice = function(group, device) {513 if (CommonService.isOriginGroup(group.class)) {514 CommonService.errorWrapper(515 DevicesService.addOriginGroupDevice516 , [group.id, device.serial])517 }518 else {519 CommonService.errorWrapper(520 GroupsService.addGroupDevice521 , [group.id, device.serial])522 .then(function(response) {523 if (!response.success &&524 response.status === 409 &&525 response.data.hasOwnProperty('conflicts')) {526 $scope.groupsEnv[group.id].showConflicts = true527 $scope.groupsEnv[group.id].conflicts = response.data.conflicts528 }529 })530 }531 }532 $scope.addGroupDevices = function(group, deviceSearch, filteredDevices) {533 CommonService.errorWrapper(534 CommonService.isOriginGroup(group.class) ?535 DevicesService.addOriginGroupDevices :536 GroupsService.addGroupDevices537 , deviceSearch ?538 [group.id, filteredDevices.map(function(device) { return device.serial }).join()] :539 [group.id])540 }541 $scope.removeGroupDevice = function(group, device) {542 CommonService.errorWrapper(543 CommonService.isOriginGroup(group.class) ?544 DevicesService.removeOriginGroupDevice :545 GroupsService.removeGroupDevice546 , [group.id, device.serial])547 }548 $scope.removeGroupDevices = function(group, deviceSearch, filteredDevices) {549 CommonService.errorWrapper(550 CommonService.isOriginGroup(group.class) ?551 DevicesService.removeOriginGroupDevices :552 GroupsService.removeGroupDevices553 , deviceSearch ?554 [group.id, filteredDevices.map(function(device) { return device.serial }).join()] :555 [group.id])556 }557 $scope.addGroupUser = function(group, user) {558 CommonService.errorWrapper(559 GroupsService.addGroupUser560 , [group.id, user.email])561 }562 $scope.addGroupUsers = function(group, userSearch, filteredUsers) {563 CommonService.errorWrapper(564 GroupsService.addGroupUsers565 , userSearch ?566 [group.id, filteredUsers.map(function(user) { return user.email }).join()] :567 [group.id])568 }569 $scope.removeGroupUser = function(group, user) {570 CommonService.errorWrapper(571 GroupsService.removeGroupUser572 , [group.id, user.email])573 }574 $scope.removeGroupUsers = function(group, userSearch, filteredUsers) {575 CommonService.errorWrapper(576 GroupsService.removeGroupUsers577 , userSearch ?578 [group.id, filteredUsers.map(function(user) { return user.email }).join()] :579 [group.id])580 }581 $scope.removeGroup = function(group, askConfirmation) {582 if (askConfirmation) {583 GenericModalService.open({584 message: 'Really delete this group?'585 , type: 'Warning'586 , size: 'sm'587 , cancel: true588 })589 .then(function() {590 CommonService.errorWrapper(591 GroupsService.removeGroup592 , [group.id])593 })594 }595 else {596 CommonService.errorWrapper(597 GroupsService.removeGroup598 , [group.id])599 }600 }601 $scope.removeGroups = function(search, filteredGroups, askConfirmation) {602 function removeGroups() {603 if (!search) {604 CommonService.errorWrapper(GroupsService.removeGroups)605 }606 else {607 CommonService.errorWrapper(608 GroupsService.removeGroups609 , [filteredGroups.map(function(group) { return group.id }).join()])610 }611 }612 if (askConfirmation) {613 GenericModalService.open({614 message: 'Really delete this selection of groups?'615 , type: 'Warning'616 , size: 'sm'617 , cancel: true618 })619 .then(function() {620 removeGroups()621 })622 }623 else {624 removeGroups()625 }626 }627 $scope.createGroup = function() {628 $scope.hideGroupCreation = true629 CommonService.errorWrapper(GroupsService.createGroup)630 .then(function() {631 delete $scope.hideGroupCreation632 })633 }634 $scope.updateGroupSchedule = function(group) {635 CommonService.errorWrapper(GroupsService.updateGroup, [group.id, {636 'class': $scope.groupsEnv[group.id].tmpClass637 , 'repetitions': parseInt($scope.groupsEnv[group.id].tmpRepetitions, 10)638 , 'startTime': $scope.groupsEnv[group.id].tmpStartDate639 , 'stopTime': $scope.groupsEnv[group.id].tmpStopDate640 }])641 .then(function(response) {642 if (!response.success &&643 response.status === 409 &&644 response.data.hasOwnProperty('conflicts')) {645 $scope.groupsEnv[group.id].conflicts = []646 response.data.conflicts.forEach(function(conflict) {647 conflict.devices.forEach(function(serial) {648 $scope.groupsEnv[group.id].conflicts.push({649 serial: serial650 , startDate: $filter('date')(conflict.date.start, SettingsService.get('dateFormat'))651 , stopDate: $filter('date')(conflict.date.stop, SettingsService.get('dateFormat'))652 , group: conflict.group653 , ownerName: conflict.owner.name654 , ownerEmail: conflict.owner.email655 })656 })657 })658 $scope.groupsEnv[group.id].showConflicts = true659 }660 })661 }662 $scope.updateGroupState = function(group) {663 CommonService.errorWrapper(664 GroupsService.updateGroup665 , [group.id, {'state': 'ready'}])666 }667 $scope.updateGroupName = function(group) {668 CommonService.errorWrapper(669 GroupsService.updateGroup670 , [group.id, {'name': $scope.groupsEnv[group.id].tmpName}])671 }672 $scope.$on('user.settings.groups.updated', function(event, message) {673 const isChangedSchedule = message.isChangedDates || message.isChangedClass674 const doGetDevices =675 !CommonService.isOriginGroup(message.group.class) &&676 (isChangedSchedule || message.devices.length)677 const isGroupOwner = $scope.isAdmin() || $scope.currentUser.email === message.group.owner.email678 const group = updateGroup(679 message.group680 , message.timeStamp681 , !isGroupOwner)682 if (group) {683 if ($scope.isAdmin()) {684 if (!CommonService.isOriginGroup(group.class)) {685 if (message.devices.length) {686 if (!message.isAddedDevice) {687 addStandardizableDevicesIfNotBooked(message.devices, message.timeStamp)688 }689 else {690 message.devices.forEach(function(serial) {691 deleteStandardizableDevice(serial, message.timeStamp)692 })693 }694 }695 }696 else if (message.isChangedClass) {697 getAvailableGroupDevices(group)698 }699 }700 if (isChangedSchedule && group.state !== 'pending') {701 $scope.initTemporarySchedule(group)702 }703 if (doGetDevices) {704 $scope.groups.forEach(function(group) {705 if (group.id !== message.group.id || isChangedSchedule) {706 getAvailableGroupDevices(group)707 }708 })709 }710 }711 else if (!isGroupOwner && doGetDevices) { // a completer ... soit propriétaire et event obsolete, soit non propriétaire donc non admin712 $scope.groups.forEach(function(group) {713 getAvailableGroupDevices(group)714 })715 }716 })717 $scope.$on('user.settings.groups.created', function(event, message) {718 addGroup(message.group, message.timeStamp)719 })720 $scope.$on('user.settings.groups.deleted', function(event, message) {721 const group = message.group722 if (deleteGroup(group.id, message.timeStamp)) {723 if ($scope.isAdmin() && !CommonService.isOriginGroup(group.class)) {724 addStandardizableDevicesIfNotBooked(group.devices, message.timeStamp)725 }726 }727 if (!CommonService.isOriginGroup(group.class) && group.devices.length) {728 $scope.groups.forEach(function(group) {729 if (!CommonService.isOriginGroup(group.class)) {730 getAvailableGroupDevices(group)731 }732 })733 }734 })735 $scope.$on('user.settings.users.updated', function(event, message) {736 function getGroupClass(id) {737 if (CommonService.isExisting(groupsById[id])) {738 return Promise.resolve($scope.groups[groupsById[id].index].class)739 }740 else if (cachedGroupsClass[id]) {741 return Promise.resolve(cachedGroupsClass[id])742 }743 else {744 return GroupsService.getGroup(id).then(function(response) {745 cachedGroupsClass[id] = response.data.group.class746 return cachedGroupsClass[id]747 })748 .catch(function(error) {749 return false750 })751 }752 }753 if (($scope.isAdmin() &&754 CommonService.isExisting($scope.usersByEmail[message.user.email]) ||755 message.user.email === $scope.currentUser.email756 ) &&757 updateUser(message.user, message.timeStamp) &&758 message.groups.length) {759 Promise.map(message.groups, function(groupId) {760 return getGroupClass(groupId).then(function(_class) {761 return !_class || _class === 'bookable'762 })763 })764 .then(function(results) {765 if (_.without(results, false).length) {766 Promise.map($scope.groups, function(group) {767 if (group.owner.email === message.user.email &&768 !CommonService.isOriginGroup(group.class)) {769 getAvailableGroupDevices(group)770 }771 })772 }773 })774 }775 })776 $scope.$on('user.settings.users.created', function(event, message) {777 addUser(message.user, message.timeStamp)778 })779 $scope.$on('user.settings.users.deleted', function(event, message) {780 deleteUser(message.user.email, message.timeStamp)781 })782 $scope.$on('user.settings.devices.deleted', function(event, message) {783 if ($scope.isAdmin()) {784 deleteOriginDevice(message.device.serial, message.timeStamp)785 deleteStandardizableDevice(message.device.serial, message.timeStamp)786 }787 $scope.groups.forEach(function(group) {788 if (!CommonService.isOriginGroup(group.class)) {789 deleteAvailableGroupDevice(group.id, message.device.serial, message.timeStamp)790 }791 })792 })793 $scope.$on('user.settings.devices.created', function(event, message) {794 const device = publishDevice(message.device)795 if ($scope.isAdmin()) {796 addOriginDevice(device, message.timeStamp)797 addStandardizableDevice(device, message.timeStamp)798 }799 })800 $scope.$on('user.settings.devices.updated', function(event, message) {801 const device = publishDevice(message.device)802 if ($scope.isAdmin()) {803 updateOriginDevice(device, message.timeStamp)804 updateStandardizableDeviceIfNotBooked(device, message.timeStamp)805 }806 $scope.groups.forEach(function(group) {807 if (!CommonService.isOriginGroup(group.class)) {808 if (device.group.origin !== message.oldOriginGroupId) {809 if ($scope.currentUser.groups.subscribed.indexOf(device.group.origin) > -1) {810 getAvailableGroupDevices(group, message.timeStamp)811 }812 else {813 deleteAvailableGroupDevice(group.id, device.serial, message.timeStamp)814 }815 }816 else {817 updateAvailableGroupDevice(group.id, device, message.timeStamp, true)818 }819 }820 })821 })822 initScope()...
Using AI Code Generation
1var stf = require('devicefarmer-stf');2stf.getAvailableGroupDevices().then(function(devices) {3 console.log(devices);4});5var stf = require('devicefarmer-stf');6stf.getDevices().then(function(devices) {7 console.log(devices);8});9var stf = require('devicefarmer-stf');10stf.getDevices().then(function(devices) {11 console.log(devices);12});13var stf = require('devicefarmer-stf');14stf.getDevices().then(function(devices) {15 console.log(devices);16});17var stf = require('devicefarmer-stf');18stf.getDevices().then(function(devices) {19 console.log(devices);20});21var stf = require('devicefarmer-stf');22stf.getDevices().then(function(devices) {23 console.log(devices);24});25var stf = require('devicefarmer-stf');26stf.getDevices().then(function(devices) {27 console.log(devices);28});29var stf = require('devicefarmer-stf');30stf.getDevices().then
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2client.getAvailableGroupDevices('group1')3.then(function(devices) {4 console.log(devices);5});6var stf = require('devicefarmer-stf-client');7client.getAvailableGroupDevices('group1')8.then(function(devices) {9 console.log(devices);10});
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2client.getAvailableGroupDevices('group name', function(err, devices) {3 if (err) {4 console.log(err);5 } else {6 console.log(devices);7 }8});9var stf = require('devicefarmer-stf-client');10getDevices(callback)11getAvailableGroupDevices(group, callback)12getAvailableDevices(callback)13getDevice(deviceId, callback)14getDeviceBySerial(serial, callback)15getDeviceByGroup(group, callback)16getDeviceByOwner(owner, callback)17getDeviceByProvider(provider, callback)18getDeviceByPresent(present, callback)19getDeviceByReady(ready, callback)20getDeviceByUsing(using, callback)21getDeviceByStatus(status, callback)22getDeviceByRemoteConnect(remoteConnect, callback)23getDeviceByRemoteConnectUrl(remoteConnectUrl, callback)24getDeviceByRemoteConnectType(remoteConnectType, callback)25getDeviceByOwnerEmail(ownerEmail, callback)26getDeviceByOwnerName(ownerName, callback)27getDeviceByOwnerGroup(ownerGroup, callback)28getDeviceByProviderEmail(providerEmail, callback)29getDeviceByProviderName(providerName, callback)30getDeviceByProviderGroup(providerGroup, callback)31getDeviceByGroupEmail(groupEmail, callback)32getDeviceByGroupName(groupName, callback)33getDeviceByGroupGroup(groupGroup, callback)34getDeviceByGroupOwnerEmail(groupOwnerEmail, callback)
Using AI Code Generation
1var Client = require('devicefarmer-stf-client');2var client = new Client();3client.getAvailableGroupDevices('group1',function(err,devices){4 if (err) {5 console.log(err);6 }7 else {8 console.log(devices);9 }10});11var Client = require('devicefarmer-stf-client');12var client = new Client();13client.getAvailableGroupDevices('group1',function(err,devices){14 if (err) {15 console.log(err);16 }17 else {18 console.log(devices);19 }20});21var Client = require('devicefarmer-stf-client');22var client = new Client();23client.getGroupDevices('group1',function(err,devices){24 if (err) {25 console.log(err);26 }27 else {28 console.log(devices);29 }30});31var Client = require('devicefarmer-stf-client');32var client = new Client();33client.getGroupDevices('group1',function(err,devices){34 if (err) {35 console.log(err);36 }37 else {38 console.log(devices);39 }40});41var Client = require('devicefarmer-stf-client');42var client = new Client();43client.getGroupDevices('group1',function(err,devices){44 if (err) {45 console.log(err);46 }47 else {48 console.log(devices);49 }50});51var Client = require('devicefarmer-stf-client');52var client = new Client();53client.getGroupDevices('group1',function(err,devices){54 if (err) {55 console.log(err);56 }57 else {58 console.log(devices);59 }60});61var Client = require('devicefarmer-stf-client');62var client = new Client();63client.getGroupDevices('group1',function(err,devices){64 if (err) {65 console.log(err);66 }67 else {68 console.log(devices);69 }70});
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2var devices = client.getAvailableGroupDevices('group-name');3console.log(devices);4var stf = require('devicefarmer-stf-client');5var devices = client.getAvailableGroupDevices('group-name');6console.log(devices);7var stf = require('devicefarmer-stf-client');8var devices = client.getAvailableGroupDevices('group-name');9console.log(devices);10var stf = require('devicefarmer-stf-client');11var devices = client.getAvailableGroupDevices('group-name');12console.log(devices);13var stf = require('devicefarmer-stf-client');14var devices = client.getAvailableGroupDevices('group-name');15console.log(devices);16var stf = require('devicefarmer-stf-client');17var devices = client.getAvailableGroupDevices('group-name');18console.log(devices);19var stf = require('devicefarmer-stf-client');20var devices = client.getAvailableGroupDevices('group-name');21console.log(devices);22var stf = require('devicefarmer-stf-client');
Using AI Code Generation
1var client = require('devicefarmer-stf-client');2stfClient.getAvailableGroupDevices('Group1',function(err,devices){3 if(err){4 console.log(err);5 }else{6 console.log(devices);7 }8});9[ { serial: 'emulator-5554',10 display: { width: 800, height: 1280 },11 network: { wifi: true, wifiIp: '
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2stfClient.getAvailableGroupDevices('group1').then(function(data){3 console.log(data);4});5var stf = require('devicefarmer-stf-client');6stfClient.getGroupDevices('group1').then(function(data){7 console.log(data);8});9var stf = require('devicefarmer-stf-client');10stfClient.getGroupDevices('group1').then(function(data){11 console.log(data);12});13var stf = require('devicefarmer-stf-client');14stfClient.getGroupDevices('group1').then(function(data){15 console.log(data);16});17var stf = require('devicefarmer-stf-client');18stfClient.getGroupDevices('group1').then(function(data){19 console.log(data);20});21var stf = require('devicefarmer-stf-client');22stfClient.getGroupDevices('group1').then(function(data){23 console.log(data);24});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!