How to use work method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

workItem.js

Source:workItem.js Github

copy

Full Screen

1const displayWorkItems = invoice => {2 const workItems = invoice.workItems || [];3 const existingContainer = document.querySelector("#work-items");4 if (existingContainer) {5 existingContainer.remove();6 }7 const workItemsContainer = document.createElement("div");8 workItemsContainer.classList.add("container");9 workItemsContainer.id = "work-items";10 // const workItemsTitle = document.createElement("h5");11 // workItemsTitle.textContent = `Invoice Work Items: ${workItems.length}`;12 // workItemsContainer.append(document.createElement("hr"));13 // workItemsContainer.append(workItemsTitle);14 const addWorkItemButton = displayAddWorkItemButton(invoice);15 workItemsContainer.append(addWorkItemButton);16 workItemsContainer.append(document.createElement("hr"));17 const headerRow = displayWorkItemHeader();18 workItemsContainer.append(headerRow);19 workItems.forEach(workItem => {20 const workItemRow = displayWorkItem(workItem);21 workItemsContainer.append(workItemRow);22 });23 const grandTotalRow = displayGrandTotalRow(invoice);24 workItemsContainer.append(grandTotalRow);25 return workItemsContainer;26};27const displayWorkItemHeader = () => {28 const headerContainer = document.createElement("div");29 headerContainer.classList.add("row");30 headerContainer.classList.add("header-row");31 ["Description", "Quantity", "Amount", "Sub-total"].forEach(32 (headerText, i) => {33 const headerCol = createCol();34 const header = document.createElement("h4");35 if (i !== 0) {36 header.style.textAlign = "right";37 }38 header.textContent = headerText;39 headerCol.append(header);40 headerContainer.append(headerCol);41 }42 );43 return headerContainer;44};45const displayWorkItem = workItem => {46 const workItemContainer = document.createElement("div");47 workItemContainer.id = `work-item-${workItem.id}`;48 workItemContainer.classList.add("row");49 workItemContainer.classList.add("work-item-row");50 const workItemDesc = createCol();51 workItemDesc.textContent = workItem.description;52 addEditListener(workItemDesc, event => {53 api54 .patchWorkItem(workItem.id, { description: event.target.textContent })55 .then(data => (event.target.textContent = data.description));56 });57 const workItemQuantity = createCol();58 workItemQuantity.classList.add("number-col");59 workItemQuantity.textContent = parseFloat(workItem.quantity);60 addEditListener(workItemQuantity, event => {61 if (isNaN(parseFloat(event.target.textContent))) {62 return;63 }64 api65 .patchWorkItem(workItem.id, {66 quantity: parseFloat(event.target.textContent)67 })68 .then(data => {69 event.target.textContent = parseFloat(data.quantity);70 updateWorkItemRowSubTotal(data);71 updateGrandTotalRow(workItem.invoice_id);72 });73 });74 const workItemAmount = createCol();75 workItemAmount.classList.add("number-col");76 workItemAmount.textContent = money(workItem.amount);77 addEditListener(workItemAmount, event => {78 const newAmount = parseFloat(79 String(event.target.textContent).replace(/[^0-9\.]/g, "")80 );81 api.patchWorkItem(workItem.id, { amount: newAmount }).then(data => {82 event.target.textContent = money(data.amount);83 updateWorkItemRowSubTotal(data);84 updateGrandTotalRow(workItem.invoice_id);85 });86 });87 const workItemSubTotal = createCol();88 workItemSubTotal.id = `work-item-subtotal-${workItem.id}`;89 workItemSubTotal.classList.add("number-col");90 workItemSubTotal.textContent = money(subTotalForWorkItem(workItem));91 const deleteBtn = document.createElement("delete");92 deleteBtn.classList = "btn btn-sm btn-danger d-print-none";93 deleteBtn.innerText = " X ";94 workItemContainer.append(95 workItemDesc,96 workItemQuantity,97 workItemAmount,98 workItemSubTotal,99 deleteBtn100 );101 //Delete workItem102 deleteBtn.addEventListener("click", event => {103 const workItemtoDelete = document.querySelector(104 `#work-item-${workItem.id}`105 );106 api.deleteWorkItem(workItem.id).then(() => {107 workItemtoDelete.remove();108 updateGrandTotalRow(workItem.invoice_id);109 });110 });111 return workItemContainer;112};113const subTotalForWorkItem = workItem => {114 const quantity = parseFloat(workItem.quantity);115 const amount = parseFloat(workItem.amount);116 return quantity * amount;117};118function money(amount) {119 return `£ ${parseFloat(amount).toFixed(2)}`;120}121const displayAddWorkItemButton = invoice => {122 const addWorkItemButton = document.createElement("button");123 ["btn", "btn-success", "d-print-none"].forEach(cls =>124 addWorkItemButton.classList.add(cls)125 );126 addWorkItemButton.textContent = "+ Add new work item";127 addWorkItemButton.addEventListener("click", () => {128 api129 .postWorkItem({130 invoice_id: invoice.id,131 description: "New work item",132 amount: 0.0,133 quantity: 0.0134 })135 .then(data => {136 document137 .querySelector("#work-items")138 .insertBefore(139 displayWorkItem(data),140 document.querySelector("#grand-total-row")141 );142 });143 });144 return addWorkItemButton;145};146function updateWorkItemRowSubTotal(workItem) {147 const subTotalCol = document.querySelector(148 `#work-item-subtotal-${workItem.id}`149 );150 if (!subTotalCol) {151 debugLog("Failed to find sub total col", { workItem });152 return;153 }154 subTotalCol.textContent = money(subTotalForWorkItem(workItem));155}156function displayGrandTotalRow(invoice) {157 const grandTotalRow = document.createElement("div");158 grandTotalRow.id = "grand-total-row";159 grandTotalRow.classList.add("row");160 grandTotalRow.classList.add("grand-total-row");161 const descriptionCol = createCol();162 descriptionCol.textContent = "GRAND TOTAL";163 grandTotalRow.append(descriptionCol);164 const quantityCol = createCol();165 quantityCol.id = "grand-quantity-col";166 quantityCol.classList.add("text-right");167 quantityCol.textContent = totalQuantityForInvoice(invoice);168 grandTotalRow.append(quantityCol);169 const placeHolderAmountCol = createCol();170 grandTotalRow.append(placeHolderAmountCol);171 const grandTotalCol = createCol();172 grandTotalCol.id = "grand-total-col";173 grandTotalCol.classList.add("text-right");174 grandTotalCol.textContent = money(grandTotalForInvoice(invoice));175 grandTotalRow.append(grandTotalCol);176 return grandTotalRow;177}178function updateGrandTotalRow(invoiceId) {179 api.getInvoice(invoiceId).then(data => {180 const quantityCol = document.querySelector("#grand-quantity-col");181 quantityCol.textContent = totalQuantityForInvoice(data);182 const grandTotalCol = document.querySelector("#grand-total-col");183 grandTotalCol.textContent = money(grandTotalForInvoice(data));184 });185}186function totalQuantityForInvoice(invoice) {187 return invoice.workItems.reduce((sum, workItem) => {188 return sum + parseFloat(workItem.quantity);189 }, 0.0);190}191function grandTotalForInvoice(invoice) {192 return invoice.workItems.reduce((sum, workItem) => {193 return sum + subTotalForWorkItem(workItem);194 }, 0.0);...

Full Screen

Full Screen

AddWorkScreen.js

Source:AddWorkScreen.js Github

copy

Full Screen

1/**2 *Author : www.juliocanares.com/cv3 *Email : juliocanares@gmail.com4 */5var APP = APP || {};6APP.AddWorkScreen = function () {7 APP.BaseScreen.call(this, 'addWork');8 this.work = null;9};10APP.AddWorkScreen.constructor = APP.AddWorkScreen;11APP.AddWorkScreen.prototype = Object.create(APP.BaseScreen.prototype);12APP.AddWorkScreen.prototype.setupUI = function () {13 this.workForm = $('.work-form');14 this.uploader = $('.uploader-work');15 this.name = $('input[name=name]');16 this.category = $('select[name=category]');17 this.description = $('textarea[name=description]');18 this.tags = $('input[name=tags]');19 this.tags.tagsInput({20 height: '50px',21 width: '100%',22 defaultText: '+Etiqueta'23 });24 this.send = $('.send');25 this.sendLoading = $('.send-loading');26 this.workDelete = $('.work-delete');27 this.workDeleteConfirm = $('.work-delete-confirm');28 this.workDeleteCancel = $('.work-delete-cancel');29 this.workDeleteForce = $('.work-delete-force');30 this.workPhotoPublished = $('.work-photo-published');31 this.workNamePublished = $('.work-name-published');32 this.workUserPublished = $('.work-user-published');33 this.workPublished = $('.work-published');34 this.workView = $('.work-view');35 this.workNew = $('.work-new');36 this.workEdit = $('.work-edit');37 this.uploaderImage = new APP.UploaderImage(this.uploader, this.imgComplete);38};39APP.AddWorkScreen.prototype.listeners = function () {40 APP.BaseScreen.prototype.listeners.call(this);41 this.workForm.submit(this.workFormSubmitHandler.bind(this));42 this.workDelete.click(this.deleteHandler.bind(this));43 this.workDeleteForce.click(this.workDeleteForceHandler.bind(this));44 this.workDeleteCancel.click(this.deleteCancel.bind(this));45 $('input[type=checkbox]').change(this.publicHandler);46};47APP.AddWorkScreen.prototype.publicHandler = function () {48 $(this).parent().find('.value').text((this.checked ? 'On' : 'Off'));49}50APP.AddWorkScreen.prototype.workFormSubmitHandler = function (event) {51 event.preventDefault();52 var errors = [],53 scope = this;54 console.log('okkk');55 if (!this.uploaderImage.photo) errors.push('Ingrese una foto');56 if (Validations.notBlank(this.name.val())) errors.push('Ingrese un nombre');57 if (Validations.notBlank(this.category.val())) errors.push('Ingrese una categoria');58 if (Validations.notBlank(this.description.val())) errors.push('Ingrese una descripcion');59 if (this.tags.val().split(',')[0].length < 1) errors.push('Ingrese etiquetas');60 if (errors.length > 0) return this.showFlash('error', errors);61 this.sendLoading.show();62 this.send.hide();63 var data = this.workForm.serializeArray();64 $.each(data, function (index, value) {65 if (value.name === 'photo')66 value.value = scope.uploaderImage.photo;67 if (value.name === 'nsfw' || value.name === 'public')68 value.value = (value.value === 'on');69 });70 var url = DataApp.currentUser.url + '/work/create';71 console.log(url)72 this.requestHandler(url, data, this.workCreatedComplete);73};74APP.AddWorkScreen.prototype.workCreatedComplete = function (response) {75 this.showFlash('succes', 'Su obra se subió exitosamente')76 this.work = response.data.work;77 this.workForm.hide();78 this.sendLoading.hide();79 this.send.show();80 var url = DataApp.currentUser.url + '/work/' + this.work.nameSlugify81 var photo = Utils.addImageFilter(this.work.photo, 'w_300,c_limit');82 this.workView.attr('href', url);83 this.workNew.attr('href', DataApp.currentUser.url + '/work/add');84 this.workEdit.attr('href', url + '/edit');85 this.workPhotoPublished.attr('src', photo);86 this.workNamePublished.text(this.work.name);87 this.workUserPublished.text(DataApp.currentUser.fullname);88 this.workPublished.show();89};90APP.AddWorkScreen.prototype.deleteHandler = function (event) {91 this.workDelete.hide();92 this.workDeleteConfirm.show();93};94APP.AddWorkScreen.prototype.workDeleteForceHandler = function () {95 var url = DataApp.currentUser.url + '/work/delete';96 this.requestHandler(url, {97 idWork: this.work.id98 }, this.forceComplete);99};100APP.AddWorkScreen.prototype.forceComplete = function () {101 this.showFlash('succes', 'Se elimino tu obra');102 setTimeout(function () {103 window.location.href = DataApp.currentUser.url;104 }, 1000);105};106APP.AddWorkScreen.prototype.deleteCancel = function (response) {107 this.workDelete.show();108 this.workDeleteConfirm.hide();109};110APP.AddWorkScreen.prototype.imgComplete = function (idImage) {111 this.$view.find('.upload').show();112 $('.cloudinary-fileupload').show();113 var filters = {114 width: 300,115 crop: 'limit'116 };117 $.cloudinary.image(idImage, filters).appendTo(this.$view.find('.preview'));...

Full Screen

Full Screen

EditWorkScreen.js

Source:EditWorkScreen.js Github

copy

Full Screen

1/**2 *Author : www.juliocanares.com/cv3 *Email : juliocanares@gmail.com4 */5var APP = APP || {};6APP.EditWorkScreen = function() {7 APP.BaseScreen.call(this, 'editWork');8 this.work = work;9 this.userWork = work.User;10};11APP.EditWorkScreen.constructor = APP.EditWorkScreen;12APP.EditWorkScreen.prototype = Object.create(APP.BaseScreen.prototype);13APP.EditWorkScreen.prototype.setupUI = function() {14 this.workForm = $('.work-form');15 this.uploaderImage = new APP.UploaderImage($('.uploader-work'), this.uploaderImageComplete);16 this.uploaderImage.photo = work.photo;17 this.name = $('input[name=name]');18 this.category = $('select[name=category]');19 $('select[name=category]').find('option[value=' + category.id + ']').attr('selected', true);20 $('input[name=public]').attr('checked', work.public);21 $('input[name=nsfw]').attr('checked', work.nsfw);22 this.description = $('textarea[name=description]');23 this.tags = $('input[name=tags]');24 this.tags.tagsInput({25 height: '50px',26 width: '100%',27 defaultText: '+Etiqueta'28 });29 this.send = $('.send');30 this.sendLoading = $('.send-loading');31 this.workDelete = $('.work-delete');32 this.workDeleteConfirm = $('.work-delete-confirm');33 this.workDeleteCancel = $('.work-delete-cancel');34 this.workDeleteForce = $('.work-delete-force');35};36APP.EditWorkScreen.prototype.listeners = function() {37 APP.BaseScreen.prototype.listeners.call(this);38 this.workForm.submit(this.workFormSubmitHandler.bind(this));39 this.workDelete.click(this.workDeleteHandler.bind(this));40 this.workDeleteForce.click(this.workDeleteForceHandler.bind(this));41 this.workDeleteCancel.click(this.workDeleteCancelHandler.bind(this));42 $('input[type=checkbox]').change(this.checkPublicHandler);43 $('input[type=checkbox]').change();44};45APP.EditWorkScreen.prototype.checkPublicHandler = function() {46 $(this).parent().find('.value').text((this.checked ? 'On' : 'Off'));47}48APP.EditWorkScreen.prototype.workFormSubmitHandler = function(event) {49 event.preventDefault();50 var errors = [],51 scope = this;52 if (!this.uploaderImage.photo) errors.push('Ingrese una foto');53 if (Validations.notBlank(this.name.val())) errors.push('Ingrese un nombre');54 if (Validations.notBlank(this.category.val())) errors.push('Ingrese una categoria');55 if (Validations.notBlank(this.description.val())) errors.push('Ingrese una descripcion');56 if (this.tags.val().split(',')[0].length < 1) errors.push('Ingrese etiquetas');57 if (errors.length > 0) return this.showFlash('error', errors);58 this.sendLoading.show();59 this.send.hide();60 var data = this.workForm.serializeArray();61 $.each(data, function(index, value) {62 if (value.name === 'photo')63 value.value = scope.uploaderImage.photo;64 if (value.name === 'nsfw' || value.name === 'public')65 value.value = (value.value === 'on');66 });67 var url = DataApp.currentUser.url + '/work/update';68 this.requestHandler(url, data, this.workUpdatedComplete);69};70APP.EditWorkScreen.prototype.workUpdatedComplete = function(response) {71 this.showFlash('succes', 'Su obra se actualizo exitosamente')72 this.work = response.data.work;73 this.sendLoading.hide();74 this.send.show();75 var url = '/user/' + this.userWork.username + '/work/' + this.work.nameSlugify;76 var timeout = setTimeout(function() {77 clearTimeout(timeout);78 window.location.href = url;79 }, 1000);80};81APP.EditWorkScreen.prototype.workDeleteHandler = function(event) {82 event.preventDefault();83 this.workDelete.hide();84 this.workDeleteConfirm.show();85};86APP.EditWorkScreen.prototype.workDeleteForceHandler = function() {87 var url = DataApp.currentUser.url + '/work/delete';88 this.requestHandler(url, {89 idWork: this.work.id90 }, this.workDeleteForceComplete);91};92APP.EditWorkScreen.prototype.workDeleteForceComplete = function() {93 this.showFlash('succes', 'Se elimino tu obra');94 var timeout = setTimeout(function() {95 clearTimeout(timeout);96 if (DataApp.currentUser.isAdmin)97 window.location.href = '/';98 else99 window.location.href = DataApp.currentUser.url;100 }, 1000);101};102APP.EditWorkScreen.prototype.workDeleteCancelHandler = function(response) {103 this.workDelete.show();104 this.workDeleteConfirm.hide();105};106APP.EditWorkScreen.prototype.uploaderImageComplete = function(idImage) {107 this.$view.find('.upload').show();108 $('.cloudinary-fileupload').show();109 var filters = {110 width: 300,111 crop: 'limit'112 };113 $.cloudinary.image(idImage, filters).appendTo(this.$view.find('.preview'));...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var client = new stf.Client();3client.work({serial: 'serial_number'}, function(err, device) {4 if (err) {5 console.error(err);6 return;7 }8 console.log(device);9 device.release(function(err) {10 if (err) {11 console.error(err);12 return;13 }14 console.log('Released');15 });16});17 this._api = new StfApi(options);18var stf = require('devicefarmer-stf-client');19var client = new stf.Client();20client.work({serial: 'serial_number'}, function(err, device) {21 if (err) {22 console.error(err);23 return;24 }25 console.log(device);26 device.release(function(err) {27 if (err) {28 console.error(err);29 return;30 }31 console.log('Released');32 });33});

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf');2var deviceFarmer = new devicefarmer.DeviceFarmer();3deviceFarmer.work('path/to/your/file.apk', 'path/to/your/test.js', function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log('Success: ' + data);8 }9});10var devicefarmer = require('devicefarmer-stf');11var deviceFarmer = new devicefarmer.DeviceFarmer();12deviceFarmer.work('path/to/your/file.apk', 'path/to/your/test.js', function(err, data) {13 if (err) {14 console.log('Error: ' + err);15 } else {16 console.log('Success: ' + data);17 }18});19var devicefarmer = require('devicefarmer-stf');20var deviceFarmer = new devicefarmer.DeviceFarmer();21deviceFarmer.work('path/to/your/file.apk', 'path/to/your/test.js', function(err, data) {22 if (err) {23 console.log('Error: ' + err);24 } else {25 console.log('Success: ' + data);26 }27});28var devicefarmer = require('devicefarmer-stf');29var deviceFarmer = new devicefarmer.DeviceFarmer();30deviceFarmer.work('path/to/your/file.apk', 'path/to/your/test.js', function(err, data) {31 if (err) {32 console.log('Error: ' + err);33 } else {34 console.log('Success: ' + data);35 }36});37var devicefarmer = require('devicefarmer-stf');38var deviceFarmer = new devicefarmer.DeviceFarmer();39deviceFarmer.work('path/to/your/file.apk', 'path/to/your/test.js', function(err, data) {40 if (err) {41 console.log('Error: ' + err);42 } else {43 console.log('Success

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf');2var device = stf.getDevice();3device.work(function(err, device) {4 device.release();5});6var stf = require('devicefarmer-stf');7var device = stf.getDevice();8device.work(function(err, device) {9 device.release();10});11var stf = require('devicefarmer-stf');12var device = stf.getDevice();13device.work(function(err, device) {14 device.release();15});16var stf = require('devicefarmer-stf');17var device = stf.getDevice();18device.work(function(err, device) {19 device.release();20});21var stf = require('devicefarmer-stf');22var device = stf.getDevice();23device.work(function(err, device) {24 device.release();25});26var stf = require('devicefarmer-stf');27var device = stf.getDevice();28device.work(function(err, device) {29 device.release();30});31var stf = require('devicefarmer-stf');32var device = stf.getDevice();33device.work(function(err, device) {34 device.release();35});36var stf = require('devicefarmer-stf');37var device = stf.getDevice();38device.work(function(err, device) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf');2var work = function(work) {3 console.log('work', work);4}5var stf = new stf.Stf(work);6stf.start();7var Stf = function(work) {8 this.work = work;9}10Stf.prototype.start = function() {11 var work = this.work;12 work('work');13}14module.exports = {15}16var request = require('request');17var Http = function() {18};19Http.prototype.get = function(url, callback) {20 request(url, function(err, res, body) {21 if (err) {22 return callback(err);23 }24 return callback(null, body);25 });26}27module.exports = Http;28var Http = require('../http');29var sinon = require('sinon');30var should = require('should');31var http = new Http();32describe('Http', function() {33 describe('get', function() {34 it('should make an HTTP request', function(done) {35 var stub = sinon.stub(request, 'get');36 stub.yields(null, 'some response');37 http.get(url, function(err, res) {38 should.not.exist(err);39 res.should.equal('some response');40 stub.restore();41 done();42 });43 });44 });45});46var stub = sinon.stub(request, 'get');

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devicefarmer-stf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful