Best JavaScript code snippet using devicefarmer-stf
Group.js
Source:Group.js
1import React from "react";2import { Accordion, Button, Card, Col, Container, Row } from "react-bootstrap";3import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";4import { UserStorage } from "storage";5import { UserAction, GroupAction } from "actions";6import { successAlert } from "utils/notification";7import { shortenString } from "utils/string";8import GroupMembersContainer from "./GroupMembersContainer";9import EmptyGroupContainer from "./EmptyGroupContainer";10import DeleteGroupModal from "./DeleteGroupModal";11import InviteUserModal from "./InviteUserModal";12import LeaveGroupModal from "./LeaveGroupModal";13import GroupHelpModal from "./GroupHelpModal";14import FeatureLock from "components/FeatureLock";15import GroupLock from "components/GroupLock";16import { LoadingSpinner, RetryBtn } from "components/spinners";17import { NetworkAvailabilityContext } from "utils/http";18class Groups extends React.Component {19 state = {20 inviteeEmail: "",21 inviteeMatricNo: "",22 isLoading: false,23 isFetching: true,24 errorFetching: false,25 newGroupName: "",26 groupName: "",27 groupMembers: [],28 deleteInvite: false,29 isGroupOwner: false,30 isUserInAnyGroup: false,31 showInviteUserModal: false,32 showLeaveGroupModal: false,33 showDeleteGroupModal: false,34 showCreateGroupModal: false,35 showHelpModal: false,36 showRemoveGroupMemberModal: {},37 inviteErrorMsg: {},38 createGroupErrorMsg: {}39 };40 static contextType = NetworkAvailabilityContext;41 componentDidMount() {42 const {43 userInfo: { email_verified, paid_for_table }44 } = UserStorage;45 if (email_verified && paid_for_table) {46 this.getGroupMembers({ showAllAlerts: false });47 }48 }49 toggleRemoveGroupMemberModal = (matricNo, deleteInvite) => {50 const { showRemoveGroupMemberModal } = this.state;51 showRemoveGroupMemberModal[matricNo] = !showRemoveGroupMemberModal[matricNo];52 this.setState({ showRemoveGroupMemberModal, deleteInvite });53 };54 toggleModal = state => {55 const { [state]: visibility } = this.state;56 this.setState({ [state]: !visibility });57 };58 /**59 * Is the currently logged in user is a group owner (updates value60 * in localstorage on change).61 */62 get isUserGroupOwner() {63 const user = UserStorage.userInfo;64 if (user == null) return false;65 return user.is_group_owner === true || user.is_group_owner === 1;66 }67 /**68 * Sets if the currently logged in user is a group owner.69 */70 set isUserGroupOwner(value) {71 UserStorage.updateUserInfo({ is_group_owner: Boolean(value) });72 this.setState({ isGroupOwner: Boolean(value) });73 }74 handleChange = event => {75 this.setState({ [event.target.name]: event.target.value });76 };77 handleInviteUser = async event => {78 event.preventDefault();79 this.setState({ isLoading: true });80 const { inviteeMatricNo: matric_no, inviteeEmail: email } = this.state;81 try {82 const { msg } = await GroupAction.inviteUser({ users: [{ matric_no, email }] });83 successAlert(msg);84 let { groupMembers } = this.state;85 // remove one null item of the list and replace it with new invitee86 groupMembers.pop();87 groupMembers.push({88 matric_no,89 email,90 firstname: "New",91 lastname: "Invitee",92 is_group_owner: false,93 joined: 094 });95 groupMembers.sort();96 this.setState({97 inviteeMatricNo: "",98 inviteeEmail: "",99 showInviteUserModal: false,100 inviteErrorMsg: {},101 groupMembers102 });103 } catch (err) {104 if (err.response) {105 const { data } = err.response;106 if (data.failed) {107 const msg = err.response.data.failed[0]["msg"];108 this.setState({ inviteErrorMsg: { all: msg } });109 }110 }111 } finally {112 this.setState({ isLoading: false });113 }114 };115 handleLeaveGroup = async event => {116 event.preventDefault();117 this.setState({ isLoading: true });118 try {119 const { msg } = await UserAction.leaveGroup();120 successAlert(msg);121 this.isUserGroupOwner = false; // updates in state and localstorage.122 this.setState({123 groupMembers: [],124 isUserInAnyGroup: false,125 showLeaveGroupModal: false,126 groupName: ""127 });128 } finally {129 this.setState({ isLoading: false });130 }131 };132 handleCreateGroup = async event => {133 event.preventDefault();134 this.setState({ isLoading: true });135 const { newGroupName: name } = this.state;136 try {137 const { msg } = await GroupAction.createGroup({ name });138 successAlert(msg);139 this.isUserGroupOwner = true; // updates in state and localstorage.140 const groupMembers = [UserStorage.userInfo];141 while (groupMembers.length <= 4) groupMembers.push(null);142 this.setState({143 newGroupName: "",144 groupName: name,145 isUserInAnyGroup: true,146 showCreateGroupModal: false,147 createGroupErrorMsg: {},148 groupMembers149 });150 } catch (err) {151 this.setState({ createGroupErrorMsg: err });152 } finally {153 this.setState({ isLoading: false });154 }155 };156 handleDeleteGroup = async event => {157 event.preventDefault();158 this.setState({ isLoading: true });159 try {160 const { msg } = await UserAction.deleteGroup();161 successAlert(msg);162 this.isUserGroupOwner = false; // updates in state and localstorage.163 this.setState({164 groupMembers: [],165 isGroupOwner: false,166 groupName: "",167 isUserInAnyGroup: false,168 showDeleteGroupModal: false169 });170 } finally {171 this.setState({ isLoading: false });172 }173 };174 handleRemoveMember = async (matricNo, deleteInvite) => {175 this.setState({ isLoading: true });176 try {177 const { msg } = await UserAction.removeMember({ matricNo, deleteInvite });178 successAlert(msg);179 let { groupMembers } = this.state;180 groupMembers = groupMembers181 .map(member => {182 if (member && member.matric_no !== matricNo) return member;183 return null;184 })185 .sort();186 this.setState({ groupMembers });187 } finally {188 let { showRemoveGroupMemberModal } = this.state;189 showRemoveGroupMemberModal[matricNo] = false;190 this.setState({ isLoading: false, showRemoveGroupMemberModal });191 }192 };193 getGroupMembers = async ({ showAllAlerts }) => {194 this.setState({195 errorFetching: false,196 isFetching: true,197 isGroupOwner: this.isUserGroupOwner198 });199 try {200 let { members, owner, name, maximum_group_members } = await UserAction.getGroup({201 showAllAlerts202 });203 owner.is_group_owner = true;204 const showRemoveGroupMemberModal = {};205 members = members.map(m => {206 let user = m.user;207 user.is_group_owner = false;208 user.joined = m.joined;209 showRemoveGroupMemberModal[user.matric_no] = false;210 return user;211 });212 /**213 * Sets the state of the group members. It fills in remaining members214 * slot left with null if total members is less than the215 * maximum_group_members allowed.216 */217 members = [owner, ...members];218 while (members.length <= maximum_group_members) members.push(null);219 this.setState({220 isUserInAnyGroup: true,221 showRemoveGroupMemberModal,222 groupName: name,223 groupMembers: members224 });225 } catch (err) {226 let errorFetching = false;227 if (err.request && err.request.status === 0) errorFetching = true;228 this.setState({ isUserInAnyGroup: false, errorFetching });229 } finally {230 this.setState({ isFetching: false });231 }232 };233 render() {234 const {235 userInfo: { email_verified, paid_for_table, matric_no: userMatricNo }236 } = UserStorage;237 const {238 handleDeleteGroup,239 handleCreateGroup,240 handleRemoveMember,241 handleLeaveGroup,242 toggleRemoveGroupMemberModal,243 handleInviteUser,244 handleChange,245 toggleModal,246 state: {247 inviteeEmail,248 inviteeMatricNo,249 groupName,250 groupMembers,251 isGroupOwner,252 isUserInAnyGroup,253 isLoading,254 isFetching,255 errorFetching,256 showRemoveGroupMemberModal,257 showCreateGroupModal,258 showDeleteGroupModal,259 deleteInvite,260 showLeaveGroupModal,261 showInviteUserModal,262 showHelpModal,263 newGroupName,264 createGroupErrorMsg,265 inviteErrorMsg266 },267 context: { offline }268 } = this;269 let notJoined = false;270 let body = null;271 if (!email_verified) {272 body = <FeatureLock />;273 } else if (!paid_for_table) {274 body = <GroupLock />;275 } else if (isFetching === true) {276 body = <LoadingSpinner />;277 } else if (errorFetching === true) {278 body = (279 <RetryBtn280 retryEvent={this.getGroupMembers}281 retryEventParams={{ showAllAlerts: false }}282 />283 );284 } else {285 if (!isGroupOwner && !isUserInAnyGroup) {286 body = (287 <EmptyGroupContainer288 handleCreateGroup={handleCreateGroup}289 isLoading={isLoading}290 createGroupErrorMsg={createGroupErrorMsg}291 showCreateGroupModal={showCreateGroupModal}292 newGroupName={newGroupName}293 handleChange={handleChange}294 toggleModal={toggleModal}295 offline={offline}296 />297 );298 } else if (isGroupOwner) {299 body = (300 <React.Fragment>301 <p style={{ textAlign: "center" }}>Invite your friends to share your joy</p>302 <div className="group-container">303 <GroupMembersContainer304 showRemoveGroupMemberModal={showRemoveGroupMemberModal}305 isLoading={isLoading}306 handleRemoveMember={handleRemoveMember}307 toggleModal={toggleModal}308 toggleRemoveGroupMemberModal={toggleRemoveGroupMemberModal}309 deleteInvite={deleteInvite}310 groupMembers={groupMembers}311 isGroupOwner={isGroupOwner}312 offline={offline}313 />314 </div>315 <InviteUserModal316 toggleModal={toggleModal}317 handleInviteUser={handleInviteUser}318 showInviteUserModal={showInviteUserModal}319 inviteErrorMsg={inviteErrorMsg}320 handleChange={handleChange}321 isLoading={isLoading}322 inviteeEmail={inviteeEmail}323 inviteeMatricNo={inviteeMatricNo}324 offline={offline}325 />326 <DeleteGroupModal327 showDeleteGroupModal={showDeleteGroupModal}328 toggleModal={toggleModal}329 isLoading={isLoading}330 handleDeleteGroup={handleDeleteGroup}331 offline={offline}332 />333 </React.Fragment>334 );335 } else if (isUserInAnyGroup === true && !isGroupOwner) {336 // Not a group admin, hence render all the members of the group user belongs to.337 let namesNotJoined = "";338 groupMembers.map(x => {339 if (x && x.joined === 0 && x.matric_no === userMatricNo) notJoined = true;340 if (x && x.joined === 0 && x.matric_no !== userMatricNo)341 namesNotJoined += `${x.firstname} ${x.lastname}, `;342 return x;343 });344 body = (345 <React.Fragment>346 {notJoined && (347 <p style={{ textAlign: "center" }}>348 You are yet to accept the invitation to this group. Check your email for349 the invitation link.350 </p>351 )}352 {namesNotJoined !== "" && (353 <p style={{ textAlign: "center" }}>354 {`${namesNotJoined} is/are yet to accept the invitation to this group`}355 </p>356 )}357 <div className="group-container not-group-admin">358 <GroupMembersContainer359 showRemoveGroupMemberModal={showRemoveGroupMemberModal}360 isLoading={isLoading}361 handleRemoveMember={handleRemoveMember}362 toggleModal={toggleModal}363 toggleRemoveGroupMemberModal={toggleRemoveGroupMemberModal}364 groupMembers={groupMembers}365 isGroupOwner={isGroupOwner}366 />367 </div>368 <LeaveGroupModal369 isLoading={isLoading}370 toggleModal={toggleModal}371 showLeaveGroupModal={showLeaveGroupModal}372 handleLeaveGroup={handleLeaveGroup}373 notJoined={notJoined}374 offline={offline}375 />376 </React.Fragment>377 );378 }379 }380 return (381 <Col xs="12" md="12">382 <Card className="material-card">383 <Card.Header>384 <h5 title={groupName !== "" ? groupName : null}>385 {groupName !== "" ? " Group: " + shortenString(groupName, 10) : "Group"}{" "}386 387 <FontAwesomeIcon388 icon="question-circle"389 title="Know more about groups"390 style={{391 cursor: "pointer"392 }}393 onClick={() => toggleModal("showHelpModal")}394 />395 </h5>396 {email_verified && paid_for_table ? (397 <React.Fragment>398 {isGroupOwner && (399 <Button400 disabled={errorFetching || offline}401 variant="outline-danger"402 onClick={() => toggleModal("showDeleteGroupModal")}403 >404 <FontAwesomeIcon icon="door-open" />405 Delete406 </Button>407 )}408 {isUserInAnyGroup && !isGroupOwner && (409 <Button410 disabled={errorFetching || offline}411 variant="outline-danger"412 onClick={() => toggleModal("showLeaveGroupModal")}413 >414 <FontAwesomeIcon icon="door-open" />415 {notJoined ? "Cancel Invite" : "Leave"}416 </Button>417 )}418 </React.Fragment>419 ) : null}420 </Card.Header>421 <Card.Body>{body}</Card.Body>422 <Accordion className="my-5">423 <Accordion.Toggle as={Card.Header} className="accordion-card" eventKey="0">424 <h5 style={{ width: "100%", cursor: "pointer" }}>425 *Special Request {" "}426 <FontAwesomeIcon427 className="text-right"428 style={{ float: "right" }}429 icon="chevron-circle-down"430 />431 </h5>432 </Accordion.Toggle>433 <Accordion.Collapse eventKey="0">434 <Card.Body>435 <Container>436 <Row>437 <Col xs="12" md="12">438 <p className="py-3">439 If you are interested in setting up a larger group with your440 friends, course mates or department, kindly send a mail to{" "}441 <a442 href="mailto:cpc@covenantuniversity.edu.ng"443 style={{ color: "purple" }}444 >445 cpc@covenantuniversity.edu.ng446 </a>{" "}447 providing the following details:448 </p>449 <ol className="ol">450 <li className="my-3">451 Your group name (452 {groupName === "" ? "Create a group" : groupName})453 </li>454 <li className="my-3">The reason for the expansion</li>455 <li className="my-3">The amount of people under your group</li>456 <li className="my-3">Your contact information</li>457 </ol>458 </Col>459 </Row>460 </Container>461 </Card.Body>462 </Accordion.Collapse>463 </Accordion>464 </Card>465 <GroupHelpModal showHelpModal={showHelpModal} toggleModal={toggleModal} />466 </Col>467 );468 }469}...
policies.js
Source:policies.js
1/**2 * Policy Mappings3 * (sails.config.policies)4 *5 * Policies are simple functions which run **before** your controllers.6 * You can apply one or more policies to a given controller, or protect7 * its actions individually.8 *9 * Any policy file (e.g. `api/policies/authenticated.js`) can be accessed10 * below by its filename, minus the extension, (e.g. "authenticated")11 *12 * For more information on how policies work, see:13 * http://sailsjs.org/#!/documentation/concepts/Policies14 *15 * For more information on configuring policies, check out:16 * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.policies.html17 */18const _ = require('lodash');19const isLogged = ['isLogged'];20const isActivityOwner = ['isActivityOwner'];21const isGroupOwner = ['isGroupOwner'];22const isResearchEntityOwner = ['isResearchEntityOwner'];23const hasValidAPIKey = ['hasValidAPIKey'];24const hasRole = require('../api/policies/hasRole.js');25const ROLES = {26 USER: 'user',27 SUPERUSER: 'superuser',28 ADMINISTRATOR: 'administrator',29 EVALUATOR: 'evaluator',30 GUEST: 'guest'31};32const defaultPolicy = {33 '*': isLogged,34 findOne: true,35 find: true,36 populate: true,37 destroy: hasRole([ROLES.ADMINISTRATOR]),38 create: hasRole([ROLES.ADMINISTRATOR]),39 update: hasRole([ROLES.ADMINISTRATOR])40};41const defaultAdminPolicy = {42 '*': hasRole([ROLES.ADMINISTRATOR]),43 findOne: hasRole([ROLES.ADMINISTRATOR]),44 find: hasRole([ROLES.ADMINISTRATOR]),45 populate: hasRole([ROLES.ADMINISTRATOR]),46 destroy: hasRole([ROLES.ADMINISTRATOR]),47 create: hasRole([ROLES.ADMINISTRATOR]),48 update: hasRole([ROLES.ADMINISTRATOR])49};50module.exports.policies = {51 /***************************************************************************52 * *53 * Default policy for all controllers and actions (`true` allows public *54 * access) *55 * *56 ***************************************************************************/57 '*': true,58 /***************************************************************************59 * *60 * Here's an example of mapping some policies to run before a controller *61 * and its actions *62 * *63 ***************************************************************************/64 AuthController: {65 '*': true66 },67 AliasController: defaultPolicy,68 AuthorshipController: defaultPolicy,69 AuthorshipGroupController: defaultPolicy,70 GroupController: _.defaults({71 getExternalDocuments: true,72 getChartsData: true,73 update: isGroupOwner,74 createDraft: isGroupOwner,75 createDrafts: isGroupOwner,76 verifyDraft: isGroupOwner,77 verifyDrafts: isGroupOwner,78 verifyDocument: isGroupOwner,79 verifyDocuments: isGroupOwner,80 discardDocument: isGroupOwner,81 discardDocuments: isGroupOwner,82 unverifyDocument: isGroupOwner,83 updateDraft: isGroupOwner,84 setAuthorships: isGroupOwner,85 deleteDraft: isGroupOwner,86 deleteDrafts: isGroupOwner,87 getPublicDocuments: true,88 getPublications: true,89 getHighImpactPublications: true,90 getFavoritePublications: true,91 getOralPresentations: true,92 getDisseminationTalks: true,93 getScientificTalks: true,94 getAccomplishments: true,95 getCompetitiveProjects: true,96 getIndustrialProjects: true,97 getPatentFamilies: true,98 getPatents: true,99 getMBOInstitutePerformance: true,100 getMBOInvitedTalks: true,101 }, defaultPolicy),102 InstituteController: defaultPolicy,103 MembershipController: defaultPolicy,104 MembershipGroupController: defaultPolicy,105 SettingsController: _.defaults({106 getSettings: true,107 }, defaultPolicy),108 SourceController: _.defaults({109 create: isLogged,110 }, defaultPolicy),111 SourceMetricSourceController: defaultPolicy,112 TaglabelController: defaultPolicy,113 UserController: _.defaults({114 jwt: true,115 getExternalDocuments: true,116 getChartsData: true,117 update: isActivityOwner,118 createDraft: isActivityOwner,119 createDrafts: isActivityOwner,120 verifyDraft: isActivityOwner,121 verifyDrafts: isActivityOwner,122 verifyDocument: isActivityOwner,123 verifyDocuments: isActivityOwner,124 discardDocument: isActivityOwner,125 discardDocuments: isActivityOwner,126 unverifyDocument: isActivityOwner,127 updateDraft: isActivityOwner,128 setAuthorships: isActivityOwner,129 deleteDraft: isActivityOwner,130 deleteDrafts: isActivityOwner,131 getPublicDocuments: true,132 getPublications: true,133 getHighImpactPublications: true,134 getFavoritePublications: true,135 getOralPresentations: true,136 getPublicProfile: hasValidAPIKey,137 getDisseminationTalks: true,138 getScientificTalks: true,139 getAccomplishments: true,140 getCompetitiveProjects: true,141 getIndustrialProjects: true,142 getPatentFamilies: true,143 getPatents: true,144 getMBOOverallPerformance: true,145 getMBOInstitutePerformance: true,146 getMBOInvitedTalks: true,147 aliases: isActivityOwner148 }, defaultPolicy),149 UserDataController: _.defaults({150 '*': hasValidAPIKey,151 getProfileImage: true152 }, defaultPolicy),153 ResearchEntityController: _.defaults({154 createDraft: isResearchEntityOwner,155 updateDraft: isResearchEntityOwner,156 deleteDraft: isResearchEntityOwner,157 verify: isResearchEntityOwner,158 unverify: isResearchEntityOwner,159 getProfile: true,160 getEditProfile: isResearchEntityOwner,161 saveProfile: isResearchEntityOwner,162 exportProfile: isResearchEntityOwner,163 minMaxYears: isLogged,164 }, defaultPolicy),165 ResearchItemTypeController: defaultPolicy,166 PublicCompetitiveProjectsController: defaultPolicy,167 ProjectStatusController: defaultPolicy,168 DocumentController: _.defaults({169 export: isLogged,170 }, defaultPolicy),171 AccomplishmentController: _.defaults({172 export: isLogged,173 }, defaultPolicy),174 ProjectController: _.defaults({175 export: isLogged,176 }, defaultPolicy),177 PatentController: _.defaults({178 export: isLogged,179 }, defaultPolicy),180 TrainingModuleController: _.defaults({181 export: isLogged,182 }, defaultPolicy),183 BackupController: _.defaults({184 getDumps: hasRole([ROLES.ADMINISTRATOR]),185 make: hasRole([ROLES.ADMINISTRATOR]),186 restore: hasRole([ROLES.ADMINISTRATOR]),187 upload: hasRole([ROLES.ADMINISTRATOR]),188 remove: hasRole([ROLES.ADMINISTRATOR]),189 download: hasRole([ROLES.ADMINISTRATOR])190 }, defaultAdminPolicy),191 CustomizeController: _.defaults({192 getCustomizations: true,193 setCustomizations: hasRole([ROLES.ADMINISTRATOR]),194 resetCustomizations: hasRole([ROLES.ADMINISTRATOR])195 }, defaultAdminPolicy),196 SourceMetricController: _.defaults({197 getMetrics: hasRole([ROLES.ADMINISTRATOR]),198 importMetrics: hasRole([ROLES.ADMINISTRATOR]),199 assignMetrics: hasRole([ROLES.ADMINISTRATOR])200 }, defaultAdminPolicy),201 LogController: _.defaults({202 getTasks: hasRole([ROLES.ADMINISTRATOR]),203 read: hasRole([ROLES.ADMINISTRATOR])204 }, defaultAdminPolicy),205 GeneralSettingsController: _.defaults({206 getByName: hasRole([ROLES.ADMINISTRATOR]),207 saveByName: hasRole([ROLES.ADMINISTRATOR])208 }, defaultAdminPolicy),209 PersonController: _.defaults({210 getUniqueRoleCategories: isLogged,211 getUniqueNationalities: isLogged212 }, defaultPolicy),213 AllMembershipController: defaultPolicy,214 AllMembershipGroupController: defaultPolicy,215 AgreementController: _.defaults({216 getUniquePartnerInstitutes: isLogged,217 export: isLogged218 }, defaultPolicy),219 PhdInstituteController: _.defaults({220 destroy: hasRole([ROLES.SUPERUSER, ROLES.ADMINISTRATOR]),221 create: hasRole([ROLES.SUPERUSER, ROLES.ADMINISTRATOR]),222 update: hasRole([ROLES.SUPERUSER, ROLES.ADMINISTRATOR])223 }, defaultPolicy),224 PhdCourseController: _.defaults({225 destroy: hasRole([ROLES.SUPERUSER, ROLES.ADMINISTRATOR]),226 create: hasRole([ROLES.SUPERUSER, ROLES.ADMINISTRATOR]),227 update: hasRole([ROLES.SUPERUSER, ROLES.ADMINISTRATOR])228 }, defaultPolicy),229 PhdCycleController: _.defaults({230 destroy: hasRole([ROLES.SUPERUSER, ROLES.ADMINISTRATOR]),231 create: hasRole([ROLES.SUPERUSER, ROLES.ADMINISTRATOR]),232 update: hasRole([ROLES.SUPERUSER, ROLES.ADMINISTRATOR])233 }, defaultPolicy),234 TaskController: _.defaults({235 run: hasRole([ROLES.SUPERUSER, ROLES.EVALUATOR, ROLES.ADMINISTRATOR]),236 isRunning: isLogged237 }, defaultAdminPolicy),238 AccessLogController: _.defaults({239 get: hasRole([ROLES.ADMINISTRATOR]),240 download: hasRole([ROLES.ADMINISTRATOR])241 }, defaultAdminPolicy),...
group.js.es6
Source:group.js.es6
1import { default as computed, observes } from 'ember-addons/ember-computed-decorators';2var Tab = Em.Object.extend({3 @computed('name')4 location(name) {5 return 'group.' + name;6 },7 @computed('name', 'i18nKey')8 message(name, i18nKey) {9 return I18n.t(`groups.${i18nKey || name}`);10 }11});12export default Ember.Controller.extend({13 application: Ember.inject.controller(),14 counts: null,15 showing: 'members',16 tabs: [17 Tab.create({ name: 'members', 'location': 'group.index', icon: 'users' }),18 Tab.create({ name: 'activity' }),19 Tab.create({20 name: 'edit', i18nKey: 'edit.title', icon: 'pencil', requiresGroupAdmin: true21 }),22 Tab.create({23 name: 'logs', i18nKey: 'logs.title', icon: 'list-alt', requiresGroupAdmin: true24 })25 ],26 @computed('model.is_group_owner', 'model.automatic')27 canEditGroup(isGroupOwner, automatic) {28 return !automatic && isGroupOwner;29 },30 @computed('model.name', 'model.full_name')31 groupName(name, fullName) {32 return (fullName || name).capitalize();33 },34 @computed('model.name', 'model.flair_url', 'model.flair_bg_color', 'model.flair_color')35 avatarFlairAttributes(groupName, flairURL, flairBgColor, flairColor) {36 return {37 primary_group_flair_url: flairURL,38 primary_group_flair_bg_color: flairBgColor,39 primary_group_flair_color: flairColor,40 primary_group_name: groupName41 };42 },43 @observes('model.user_count')44 _setMembersTabCount() {45 this.get('tabs')[0].set('count', this.get('model.user_count'));46 },47 @computed('model.is_group_user', 'model.is_group_owner', 'model.automatic')48 getTabs(isGroupUser, isGroupOwner, automatic) {49 return this.get('tabs').filter(t => {50 let display = true;51 if (this.currentUser && t.get('requiresGroupAdmin')) {52 display = automatic ? false : (this.currentUser.admin || isGroupOwner);53 } else if (t.get('requiresGroupAdmin')) {54 display = false;55 }56 return display;57 });58 }...
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2client.isGroupOwner('deviceID').then(function (isOwner) {3 console.log(isOwner);4});5var stf = require('devicefarmer-stf-client');6client.isGroupOwner('deviceID').then(function (isOwner) {7 if (isOwner) {8 console.log('Device is the owner of the group');9 } else {10 console.log('Device is not the owner of the group');11 }12});13var stf = require('devicefarmer-stf-client');14client.isGroupOwner('deviceID').then(function (isOwner) {15 if (isOwner) {16 console.log('Device is the owner of the group');17 } else {18 console.log('Device is not the owner of the group');19 }20});
Using AI Code Generation
1var df = require('devicefarmer-stf');2df.getDevices().then(function(devices){3 for(var i=0;i<devices.length;i++){4 var device = devices[i];5 if(device.isGroupOwner()) {6 console.log(device.serial);7 }8 }9});
Using AI Code Generation
1var client = require('devicefarmer-stf-client');2var stf = new client.STFClient();3stf.on('connect', function() {4 stf.isGroupOwner('device_id', function(error, result) {5 if (error) {6 console.log('error: ', error);7 } else {8 console.log('result: ', result);9 }10 });11});12stf.connect(url, username, password);13stf.disconnect();14stf.on(event, callback);15- event name (see Events)16stf.off(event, callback);17- event name (see Events)18stf.getDevices(callback);19stf.getDevice(serial, callback);20stf.getDeviceByToken(token, callback);21stf.getDeviceByGroup(group, callback);22stf.getDeviceByGroupOwner(groupOwner, callback);23stf.getDeviceByOwner(owner, callback);24stf.getDeviceByProvider(provider, callback);25stf.getDeviceByStatus(status, callback);26stf.getDeviceByType(type, callback);
Using AI Code Generation
1var stfClient = require('devicefarmer-stf-client');2var stf = new stfClient();3stf.isGroupOwner('device_id', function(error, isOwner) {4 console.log('isOwner: ' + isOwner);5});6var stfClient = require('devicefarmer-stf-client');7var stf = new stfClient();8stf.getGroupOwner('device_id', function(error, owner) {9 console.log('owner: ' + owner);10});11var stfClient = require('devicefarmer-stf-client');12var stf = new stfClient();13stf.getGroupDevices('device_id', function(error, devices) {14 console.log('devices: ' + devices);15});16var stfClient = require('devicefarmer-stf-client');17var stf = new stfClient();18stf.getGroupDevices('device_id', function(error, devices) {19 console.log('devices: ' + devices);20});21var stfClient = require('devicefarmer-stf-client');22var stf = new stfClient();23stf.getGroupDevices('device_id', function(error, devices) {24 console.log('devices: ' + devices);25});26var stfClient = require('devicefarmer-stf-client');27var stf = new stfClient();28stf.getGroupDevices('device_id', function(error, devices) {29 console.log('devices: ' + devices);30});31var stfClient = require('devicefarmer-stf-client');32var stf = new stfClient();33stf.getGroupDevices('device_id', function(error, devices) {34 console.log('devices: ' + devices);35});
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2device.isGroupOwner('device serial', function(error, result){3 if(error){4 console.log(error);5 }6 else{7 console.log(result);8 }9});10var stf = require('devicefarmer-stf-client');11device.listDevices(function(error, result){12 if(error){13 console.log(error);14 }15 else{16 console.log(result);17 }18});19var stf = require('devicefarmer-stf-client');20device.listGroups(function(error, result){21 if(error){22 console.log(error);23 }24 else{25 console.log(result);26 }27});28var stf = require('devicefarmer-stf-client');29device.listGroups(function(error, result){30 if(error){31 console.log(error);32 }33 else{34 console.log(result);35 }36});37var stf = require('devicefarmer-stf-client');38device.listUsers(function(error, result){39 if(error){40 console.log(error);41 }42 else{43 console.log(result);44 }45});46var stf = require('devicefarmer-stf-client');47device.removeDevice('device serial', function(error, result){48 if(error){49 console.log(error);50 }51 else{52 console.log(result);53 }54});55var stf = require('devicefarmer-stf-client');
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!!