Best JavaScript code snippet using devicefarmer-stf
device-column-service.js
Source:device-column-service.js
...359 else {360 return la < lb ? -1 : 1361 }362}363function filterIgnoreCase(a, filterValue) {364 var va = (a || '').toLowerCase()365 var vb = filterValue.toLowerCase()366 return va.indexOf(vb) !== -1367}368function compareRespectCase(a, b) {369 if (a === b) {370 return 0371 }372 else {373 return a < b ? -1 : 1374 }375}376function TextCell(options) {377 return _.defaults(options, {378 title: options.title379 , defaultOrder: 'asc'380 , build: function () {381 var td = document.createElement('td')382 td.appendChild(document.createTextNode(''))383 return td384 }385 , update: function (td, item) {386 var t = td.firstChild387 t.nodeValue = options.value(item)388 return td389 }390 , compare: function (a, b) {391 return compareIgnoreCase(options.value(a), options.value(b))392 }393 , filter: function (item, filter) {394 return filterIgnoreCase(options.value(item), filter.query)395 }396 })397}398function DeviceTypeCell(options) {399 return _.defaults(options, {400 title: options.title401 , defaultOrder: 'asc'402 , build: function () {403 var td = document.createElement('td')404 td.appendChild(document.createTextNode(''))405 return td406 }407 , update: function (td, device) {408 var t = td.firstChild409 if (device.deviceType && device.deviceType == "ç°åºæµè¯") {410 td.className = 'WheatColor'411 } else {412 td.className = 'Gainsboro'413 }414 t.nodeValue = options.value(device)415 return td416 }417 , compare: function (a, b) {418 return compareIgnoreCase(options.value(a), options.value(b))419 }420 , filter: function (item, filter) {421 return filterIgnoreCase(options.value(item), filter.query)422 }423 })424}425function NumberCell(options) {426 return _.defaults(options, {427 title: options.title428 , defaultOrder: 'asc'429 , build: function () {430 var td = document.createElement('td')431 td.appendChild(document.createTextNode(''))432 return td433 }434 , update: function (td, item) {435 var t = td.firstChild436 t.nodeValue = options.format(options.value(item))437 return td438 }439 , compare: function (a, b) {440 var va = options.value(a) || 0441 var vb = options.value(b) || 0442 return va - vb443 }444 , filter: (function () {445 return function (item, filter) {446 return filterOps[filter.op || '='](447 options.value(item)448 , Number(filter.query)449 )450 }451 })()452 })453}454function DateCell(options) {455 return _.defaults(options, {456 title: options.title457 , defaultOrder: 'desc'458 , build: function () {459 var td = document.createElement('td')460 td.appendChild(document.createTextNode(''))461 return td462 }463 , update: function (td, item) {464 var t = td.firstChild465 var date = options.value(item)466 if (date) {467 t.nodeValue = date.getFullYear()468 + '-'469 + zeroPadTwoDigit(date.getMonth() + 1)470 + '-'471 + zeroPadTwoDigit(date.getDate())472 }473 else {474 t.nodeValue = ''475 }476 return td477 }478 , compare: function (a, b) {479 var va = options.value(a) || 0480 var vb = options.value(b) || 0481 return va - vb482 }483 , filter: (function () {484 function dateNumber(d) {485 return d486 ? d.getFullYear() * 10000 + d.getMonth() * 100 + d.getDate()487 : 0488 }489 return function (item, filter) {490 var filterDate = new Date(filter.query)491 var va = dateNumber(options.value(item))492 var vb = dateNumber(filterDate)493 return filterOps[filter.op || '='](va, vb)494 }495 })()496 })497}498function LinkCell(options) {499 return _.defaults(options, {500 title: options.title501 , defaultOrder: 'asc'502 , build: function () {503 var td = document.createElement('td')504 var a = document.createElement('a')505 a.appendChild(document.createTextNode(''))506 td.appendChild(a)507 return td508 }509 , update: function (td, item) {510 var a = td.firstChild511 var t = a.firstChild512 var href = options.link(item)513 if (href) {514 a.setAttribute('href', href)515 }516 else {517 a.removeAttribute('href')518 }519 a.target = options.target || ''520 t.nodeValue = options.value(item)521 return td522 }523 , compare: function (a, b) {524 return compareIgnoreCase(options.value(a), options.value(b))525 }526 , filter: function (item, filter) {527 return filterIgnoreCase(options.value(item), filter.query)528 }529 })530}531function DeviceBrowserCell(options) {532 return _.defaults(options, {533 title: options.title534 , defaultOrder: 'asc'535 , build: function () {536 var td = document.createElement('td')537 var span = document.createElement('span')538 span.className = 'device-browser-list'539 td.appendChild(span)540 return td541 }542 , update: function (td, device) {543 var span = td.firstChild544 var browser = options.value(device)545 var apps = browser.apps.slice().sort(function (appA, appB) {546 return compareIgnoreCase(appA.name, appB.name)547 })548 for (var i = 0, l = apps.length; i < l; ++i) {549 var app = apps[i]550 var img = span.childNodes[i] || span.appendChild(document.createElement('img'))551 var src = '/static/app/browsers/icon/36x36/' + (app.type || '_default') + '.png'552 // Only change if necessary so that we don't trigger a download553 if (img.getAttribute('src') !== src) {554 img.setAttribute('src', src)555 }556 img.title = app.name + ' (' + app.developer + ')'557 }558 while (span.childNodes.length > browser.apps.length) {559 span.removeChild(span.lastChild)560 }561 return td562 }563 , compare: function (a, b) {564 return options.value(a).apps.length - options.value(b).apps.length565 }566 , filter: function (device, filter) {567 return options.value(device).apps.some(function (app) {568 return filterIgnoreCase(app.type, filter.query)569 })570 }571 })572}573function DeviceModelCell(options) {574 return _.defaults(options, {575 title: options.title576 , defaultOrder: 'asc'577 , build: function () {578 var td = document.createElement('td')579 var span = document.createElement('span')580 var image = document.createElement('img')581 span.className = 'device-small-image'582 image.className = 'device-small-image-img pointer'583 span.appendChild(image)584 td.appendChild(span)585 td.appendChild(document.createTextNode(''))586 return td587 }588 , update: function (td, device) {589 var span = td.firstChild590 var image = span.firstChild591 var t = span.nextSibling592 var src = '/static/app/devices/icon/x24/' +593 (device.image || '_default.jpg')594 // Only change if necessary so that we don't trigger a download595 if (image.getAttribute('src') !== src) {596 image.setAttribute('src', src)597 }598 t.nodeValue = options.value(device)599 return td600 }601 , compare: function (a, b) {602 return compareRespectCase(options.value(a), options.value(b))603 }604 , filter: function (device, filter) {605 return filterIgnoreCase(options.value(device), filter.query)606 }607 })608}609function DeviceNameCell(options) {610 return _.defaults(options, {611 title: options.title612 , defaultOrder: 'asc'613 , build: function () {614 var td = document.createElement('td')615 var a = document.createElement('a')616 a.appendChild(document.createTextNode(''))617 td.appendChild(a)618 return td619 }620 , update: function (td, device) {621 var a = td.firstChild622 var t = a.firstChild623 if (device.using) {624 a.className = 'device-product-name-using'625 a.href = '#!/control/' + device.serial626 }627 else if (device.usable) {628 a.className = 'device-product-name-usable'629 a.href = '#!/control/' + device.serial630 }631 else {632 a.className = 'device-product-name-unusable'633 a.removeAttribute('href')634 }635 t.nodeValue = options.value(device)636 return td637 }638 , compare: function (a, b) {639 return compareIgnoreCase(options.value(a), options.value(b))640 }641 , filter: function (device, filter) {642 return filterIgnoreCase(options.value(device), filter.query)643 }644 })645}646function DeviceRentReleaseCell(options, DeviceRentService, $location, AppState, GroupService, socket) {647 var stateClasses = {648 using: 'state-using btn-primary'649 , busy: 'state-busy btn-warning'650 , available: 'state-available btn-primary-outline'651 , ready: 'state-ready btn-primary-outline'652 , present: 'state-present btn-primary-outline'653 , preparing: 'state-preparing btn-primary-outline btn-success-outline'654 , unauthorized: 'state-unauthorized btn-danger-outline'655 , offline: 'state-offline btn-warning-outline'656 , automation: 'state-automation btn-info'657 }658 return _.defaults(options, {659 title: options.title660 , defaultOrder: 'asc'661 , build: function () {662 var td = document.createElement('td')663 var a = document.createElement('a')664 a.appendChild(document.createTextNode(''))665 td.appendChild(a)666 return td667 }668 , update: function (td, device) {669 var a = td.firstChild670 var t = a.firstChild671 user = AppState.user672 var para = arguments673 if (device.device_rent_conf &&674 device.device_rent_conf.rent &&675 device.device_rent_conf.owner &&676 device.device_rent_conf.owner.email &&677 device.device_rent_conf.owner.name &&678 user) {679 if (user.name == device.device_rent_conf.owner.name &&680 user.email == device.device_rent_conf.owner.email) {681 a.className = 'pointer btn btn-xs device-rent-release-status btn-outline-rent rowhover'682 } else {683 a.className = 'pointer-not-allowed btn btn-xs device-rent-release-status black-font-color'684 }685 } else {686 a.className = 'pointer btn btn-xs device-rent-release-status' +687 (stateClasses[device.state] || 'btn-default-outline')688 }689 a.onclick = function (e) {690 user = AppState.user691 var para = arguments692 /*693 if (device.device_rent_conf &&694 device.device_rent_conf.rent) {695 if (device.device_rent_conf.owner &&696 device.device_rent_conf.owner.email &&697 device.device_rent_conf.owner.name &&698 user) {699 if (user.name == device.device_rent_conf.owner.name &&700 user.email == device.device_rent_conf.owner.email) {701 if (confirm('ä½ ç¡®å®éè¦åæ¢ç§ç¨åï¼')) {702 GroupService.kick(device, true)703 DeviceRentService.free_rent(device, socket)704 e.preventDefault()705 }706 }707 }708 }709 else {710 return Promise.all([device].map(function (device) {711 e.preventDefault()712 return DeviceRentService.open(device)713 })).then(function (result) {714 if (result[0].result == true) {715 $location.path('/control/' + result[0].device.serial);716 }717 })718 .catch(function (err) {719 console.log('err: ', err)720 })721 }722 */723 // e.preventDefault()724 };725 t.nodeValue = options.value(device)726 return td727 }728 , compare: function (a, b) {729 return options.value(a) - options.value(b)730 }731 , filter: function (device, filter) {732 return filterIgnoreCase(options.value(device), filter.query)733 }734 })735}736function DeviceBackCell(options) {737 var stateClasses = {738 using: 'state-using btn-primary'739 , busy: 'state-busy btn-warning'740 , available: 'state-available btn-primary-outline'741 , ready: 'state-ready btn-primary-outline'742 , present: 'state-present btn-primary-outline'743 , preparing: 'state-preparing btn-primary-outline btn-success-outline'744 , unauthorized: 'state-unauthorized btn-danger-outline'745 , offline: 'state-offline btn-warning-outline'746 , automation: 'state-automation btn-info'747 }748 return _.defaults(options, {749 title: options.title750 , defaultOrder: 'asc'751 , build: function () {752 var td = document.createElement('td')753 var a = document.createElement('a')754 a.appendChild(document.createTextNode(''))755 td.appendChild(a)756 return td757 }758 , update: function (td, device) {759 var a = td.firstChild760 var t = a.firstChild761 if (device.deviceType.trim() == 'ç°åºæµè¯') {762 //åªå¯¹ç°åºè®¾å¤è¿è¡å½è¿763 if (!device.back || (device.back && device.back == '0')) {764 //back为0ï¼æ¾ç¤ºå½è¿765 //æ backå段ï¼ä¸ç®¡æ¯å¦ååºï¼ç»ä¸æ¾ç¤ºå½è¿ï¼å
¼å®¹æ§æ°æ®å¯ä½å½è¿æä½766 a.className = 'btn btn-xs rowhover device-back-status'767 t.nodeValue = 'å½è¿'768 }769 else {770 //back为1ï¼æ¾ç¤ºå·²å½è¿771 //back为nullï¼æ¾ç¤ºå·²å½è¿772 a.className = 'btn btn-xs a-disabled'773 t.nodeValue = 'å·²å½è¿'774 }775 }776 else {777 a.className = 'btn btn-xs a-disabled'778 t.nodeValue = 'å½è¿'779 }780 a.removeAttribute('href')781 return td782 }783 , compare: function (a, b) {784 return compareIgnoreCase(options.value(a), options.value(b))785 }786 , filter: function (device, filter) {787 return filterIgnoreCase(options.value(device), filter.query)788 }789 })790}791function DeviceRentCell(options, DeviceRentService, $location, AppState, GroupService, socket) {792 var stateClasses = {793 using: 'state-using btn-primary'794 , busy: 'state-busy btn-warning'795 , available: 'state-available btn-primary-outline'796 , ready: 'state-ready btn-primary-outline'797 , present: 'state-present btn-primary-outline'798 , preparing: 'state-preparing btn-primary-outline btn-success-outline'799 , unauthorized: 'state-unauthorized btn-danger-outline'800 , offline: 'state-offline btn-warning-outline'801 , automation: 'state-automation btn-info'802 }803 return _.defaults(options, {804 title: options.title805 , defaultOrder: 'asc'806 , build: function () {807 var td = document.createElement('td')808 var a = document.createElement('a')809 a.appendChild(document.createTextNode(''))810 td.appendChild(a)811 return td812 }813 , update: function (td, device) {814 var a = td.firstChild815 var t = a.firstChild816 if (device.device_rent_conf && device.device_rent_conf.rent && !stateClasses[device.state]) {817 a.className = 'btn btn-xs device-rent-status btn-outline-rent rowhover '818 } else if (device.deviceType == 'ç°åºæµè¯') {819 a.className = 'btn btn-xs device-rent-status state-available btn-primary-outline'820 }821 else {822 a.className = 'btn btn-xs device-rent-status ' +823 (stateClasses[device.state] || 'btn-default-outline')824 }825 if (device.usable && (device.state == 'available' || device.state == 'using')) {826 a.href = '#!/control/' + device.serial827 }828 else {829 a.removeAttribute('href')830 }831 t.nodeValue = options.value(device)832 return td833 }834 , compare: function (a, b) {835 return compareIgnoreCase(options.value(a), options.value(b))836 }837 , filter: function (device, filter) {838 return filterIgnoreCase(options.value(device), filter.query)839 }840 })841}842function DeviceRentProjectCell(options) {843 return _.defaults(options, {844 title: options.title845 , defaultOrder: 'asc'846 , build: function () {847 var td = document.createElement('td')848 var span = document.createElement('span')849 span.className = 'device-browser-list'850 td.appendChild(span)851 return td852 }853 , update: function (td, device) {854 var span = td.firstChild855 var browser = options.value(device)856 var apps = browser.apps.slice().sort(function (appA, appB) {857 return compareIgnoreCase(appA.name, appB.name)858 })859 for (var i = 0, l = apps.length; i < l; ++i) {860 var app = apps[i]861 var img = span.childNodes[i] || span.appendChild(document.createElement('img'))862 var src = '/static/app/browsers/icon/36x36/' + (app.type || '_default') + '.png'863 // Only change if necessary so that we don't trigger a download864 if (img.getAttribute('src') !== src) {865 img.setAttribute('src', src)866 }867 img.title = app.name + ' (' + app.developer + ')'868 }869 while (span.childNodes.length > browser.apps.length) {870 span.removeChild(span.lastChild)871 }872 return td873 }874 , compare: function (a, b) {875 return compareIgnoreCase(options.value(a), options.value(b))876 }877 , filter: function (device, filter) {878 return options.value(device).apps.some(function (app) {879 return filterIgnoreCase(app.type, filter.query)880 })881 }882 })883}884function DeviceStatusCell(options) {885 var stateClasses = {886 using: 'state-using btn-primary'887 , busy: 'state-busy btn-warning'888 , available: 'state-available btn-primary-outline'889 , ready: 'state-ready btn-primary-outline'890 , present: 'state-present btn-primary-outline'891 , preparing: 'state-preparing btn-primary-outline btn-success-outline'892 , unauthorized: 'state-unauthorized btn-danger-outline'893 , offline: 'state-offline btn-warning-outline'894 , automation: 'state-automation btn-info'895 , maintain: 'maintaincolor'896 }897 return _.defaults(options, {898 title: options.title899 , defaultOrder: 'asc'900 , build: function () {901 var td = document.createElement('td')902 var a = document.createElement('a')903 a.appendChild(document.createTextNode(''))904 td.appendChild(a)905 return td906 }907 , update: function (td, device) {908 var a = td.firstChild909 var t = a.firstChild910 a.className = 'btn btn-xs device-status ' +911 (stateClasses[device.state] || 'btn-default-outline')912 if (device.usable || device.state === 'Busy' || device.state === 'available') {913 a.href = '#!/control/' + device.serial914 }915 else {916 a.removeAttribute('href')917 }918 t.nodeValue = options.value(device)919 return td920 }921 , compare: function (a, b) {922 return compareIgnoreCase(options.value(a), options.value(b))923 }924 , filter: function (device, filter) {925 return filterIgnoreCase(options.value(device), filter.query)926 }927 })928}929function DeviceNoteCell(options) {930 return _.defaults(options, {931 title: options.title932 , defaultOrder: 'asc'933 , build: function () {934 var td = document.createElement('td')935 var span = document.createElement('span')936 var i = document.createElement('i')937 td.className = 'device-note'938 span.className = 'xeditable-wrapper'939 span.appendChild(document.createTextNode(''))940 i.className = 'device-note-edit fa fa-pencil pointer'941 td.appendChild(span)942 td.appendChild(i)943 return td944 }945 , update: function (td, item) {946 var span = td.firstChild947 var t = span.firstChild948 t.nodeValue = options.value(item)949 return td950 }951 , compare: function (a, b) {952 return compareIgnoreCase(options.value(a), options.value(b))953 }954 , filter: function (item, filter) {955 return filterIgnoreCase(options.value(item), filter.query)956 }957 })958}959function DeviceMaintainCell(options) {960 return _.defaults(options, {961 title: options.title962 , defaultOrder: 'asc'963 , build: function () {964 var td = document.createElement('td')965 var button = document.createElement('button')966 var i = document.createElement('i')967 var span = document.createElement('span')968 button.className = 'device-maintain-edit device-maintain-button'969 td.className = 'device-maintain'970 span.className = 'device-maintain-edit device-maintain-text'971 span.appendChild(document.createTextNode(''))972 i.className = 'fa fa-wrench device-maintain-edit'973 td.appendChild(button)974 button.appendChild(span)975 button.appendChild(i)976 return td977 }978 , update: function (td, item) {979 var span = td.firstChild.firstChild980 var t = span.firstChild981 console.log("coloum æ´æ°æ¥ä¿®ç¶æï¼" + options.value(item))982 if (options.value(item)) {983 t.nodeValue = 'åæ¶æ¥ä¿®'984 } else {985 t.nodeValue = 'æ¥ä¿®'986 }987 // t.nodeValue = options.value(item)988 return td989 }990 , compare: function (a, b) {991 return compareIgnoreCase(options.value(a), options.value(b))992 }993 , filter: function (item, filter) {994 return filterIgnoreCase(options.value(item), filter.query)995 }996 })...
skills.js
Source:skills.js
1import React from 'react'2import Highlight from 'react-highlight-words'3import {4 Table,5 TableBody,6 TableCell,7 TableHead,8 TableSortLabel,9 TextField,10 Checkbox,11 FormControlLabel,12} from '@material-ui/core'1314import Layout from '../components/Layout'15import skillsData from './../data/skills'16import SEO from '../components/SEO'17import Header from '../components/Header'18import TableRowMobile from '../components/TableRowMobile'1920const categories = ['Technology', 'Description']2122class Skills extends React.Component {23 state = {24 activeLabel: 'Technology',25 activeDirection: 'desc',26 filter: '',27 filterRegExp: new RegExp(''),28 filterIgnoreCase: true,29 filterExclude: {},30 }3132 labelClickHandler = (event) => {33 const name = event.currentTarget.getAttribute('name')34 if (this.state.activeLabel === name) {35 const activeDirection = this.state.activeDirection === 'asc' ? 'desc' : 'asc'36 this.setState({activeDirection})37 }38 else {39 const activeLabel = name40 const activeDirection = 'desc'41 this.setState({activeLabel, activeDirection})42 }43 }4445 filterHandler = (event) => {46 try {47 const filter = event.target.value.replace(/(\\|\^|\$|\*|\+|\?|\.|\(|\)|\{|\}|\[|\])/g, '\\$1')48 const filterRegExp = new RegExp(filter, this.state.filterIgnoreCase ? 'i' : '')49 this.setState({filter: event.target.value, filterRegExp})50 }51 catch (err) {52 console.error(err.message)53 this.setState({filter: event.target.value})54 }55 }5657 filterIgnoreCaseHandler = (event) => {58 try {59 const filter = this.state.filter.replace(/(\\|\^|\$|\*|\+|\?|\.|\(|\)|\{|\}|\[|\])/g, '\\$1')60 const filterRegExp = new RegExp(filter, event.target.checked ? 'i' : '')61 this.setState({filterIgnoreCase: event.target.checked, filterRegExp})62 }63 catch (err) {64 console.error(err.message)65 this.setState({filterIgnoreCase: event.target.checked})66 }67 }6869 sortTableHandler = (a, b) => {70 // sorts strings alphabetically and numbers numerically71 a = a[this.state.activeLabel]72 b = b[this.state.activeLabel]7374 if (typeof a === 'string') {75 a = a.toLowerCase()76 b = b.toLowerCase()77 }7879 if (Array.isArray(a)) {80 a = a.join('\n').length81 b = b.join('\n').length82 }8384 if (a === b) return 08586 if (a < b) {87 if (this.state.activeDirection === 'asc') {88 return 189 }90 else {91 return -192 }93 }9495 if (a > b) {96 if (this.state.activeDirection === 'asc') {97 return -198 }99 else {100 return 1101 }102 }103 }104105 filterTableHandler = (skill) => {106 if (!this.state.filter) return true107108 for (let category of categories) {109 if (!this.state.filterExclude[category] && this.state.filterRegExp.test(skill[category])) return true110 }111 112 return false113 }114115 render() {116 return (117 <Layout>118119 <SEO title='Skills' path='/skills'/>120 <Header title='Skills' next='Projects' path={'/projects'}/>121122 <TextField123 label='Filter'124 placeholder='Use | to multi-filter: C++|Python'125 style={{width: '100%'}}126 value={this.state.filter}127 onChange={this.filterHandler}128 />129 130 <FormControlLabel label='Ignore Case' control={131 <Checkbox132 style={{color: '#4078c0'}}133 color='primary'134 checked={this.state.filterIgnoreCase}135 onChange={this.filterIgnoreCaseHandler}136 />137 }/>138139 {categories.map(category => (140 <FormControlLabel key={category} label={`Apply to ${category}`} control={141 <Checkbox142 style={{color: '#4078c0'}}143 color='primary'144 checked={!this.state.filterExclude[category]}145 onChange={(e) => {146 this.state.filterExclude[category] = !e.target.checked147 this.setState({filterExclude: this.state.filterExclude})148 }}149 />150 }/>151 ))}152153 <Table style={{width: '100%'}} size='small'>154 <TableHead>155 <TableRowMobile>156 {categories.map(category => (157 <TableCell key={category}>158 <TableSortLabel159 name={category}160 style={{fontWeight: 'bold'}}161 onClick={this.labelClickHandler}162 active={this.state.activeLabel === category}163 direction={this.state.activeLabel === category ? this.state.activeDirection : 'desc'}>164 {category}165 </TableSortLabel>166 </TableCell>167 ))}168 </TableRowMobile>169 </TableHead>170171 <TableBody>172 {skillsData173 .filter(this.filterTableHandler)174 .sort(this.sortTableHandler)175 .map((skill) => (176 <TableRowMobile key={skill.Technology}>177 <TableCell>178 <a href={skill.Website} target="_blank" rel="external nofollow">179 <Highlight180 caseSensitive={!this.state.filterIgnoreCase}181 searchWords={[!this.state.filterExclude.Technology ? this.state.filterRegExp : '']}182 textToHighlight={skill.Technology}183 />184 </a>185 </TableCell>186 <TableCell>187 <ul style={{paddingLeft: '1rem'}}>188 {skill.Description.map((bullet, i) => (189 <li key={i}>190 <Highlight191 caseSensitive={!this.state.filterIgnoreCase}192 searchWords={[!this.state.filterExclude.Description ? this.state.filterRegExp : '']}193 textToHighlight={bullet}194 />195 </li>196 ))}197 </ul>198 </TableCell>199 </TableRowMobile>200 ))}201 </TableBody>202 </Table>203204 </Layout>205 )206 }207}208
...
index.js
Source:index.js
1/*2 * Copyright © 2016 Cask Data, Inc.3 *4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not5 * use this file except in compliance with the License. You may obtain a copy of6 * the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13 * License for the specific language governing permissions and limitations under14 * the License.15 */16import React, { Component, PropTypes } from 'react';17import WranglerStore from 'wrangler/components/Wrangler/Store/WranglerStore';18import WranglerActions from 'wrangler/components/Wrangler/Store/WranglerActions';19import classnames from 'classnames';20import {Tooltip} from 'reactstrap';21import T from 'i18n-react';22export default class Filter extends Component {23 constructor(props) {24 super(props);25 this.state = {26 showFilter: false,27 filterIgnoreCase: false,28 filterFunction: '=',29 tooltipOpen: false30 };31 this.onFilterClick = this.onFilterClick.bind(this);32 this.onFilter = this.onFilter.bind(this);33 this.toggleTooltip = this.toggleTooltip.bind(this);34 this.handleKeyPress = this.handleKeyPress.bind(this);35 }36 toggleTooltip() {37 this.setState({tooltipOpen: !this.state.tooltipOpen});38 }39 onFilterClick() {40 if (!this.props.column) { return; }41 this.setState({showFilter: !this.state.showFilter});42 }43 handleKeyPress(e) {44 if (e.nativeEvent.keyCode === 13) {45 this.onFilter();46 }47 }48 renderFilter() {49 if (!this.state.showFilter || !this.props.column) { return null; }50 return (51 <div52 className="filter-input"53 onClick={e => e.stopPropagation()}54 >55 <select56 className="form-control"57 onChange={e => this.setState({filterFunction: e.target.value})}58 value={this.state.filterFunction}59 >60 <option value="=">{T.translate('features.Wrangler.Filter.Options.equal')}</option>61 <option value="!=">{T.translate('features.Wrangler.Filter.Options.doesNotEqual')}</option>62 <option value="<">{T.translate('features.Wrangler.Filter.Options.lessThan')}</option>63 <option value=">">{T.translate('features.Wrangler.Filter.Options.greaterThan')}</option>64 <option value="<=">{T.translate('features.Wrangler.Filter.Options.lessEqual')}</option>65 <option value=">=">{T.translate('features.Wrangler.Filter.Options.greaterEqual')}</option>66 <option value="startsWith">{T.translate('features.Wrangler.Filter.Options.startsWith')}</option>67 <option value="endsWith">{T.translate('features.Wrangler.Filter.Options.endsWith')}</option>68 <option value="contains">{T.translate('features.Wrangler.Filter.Options.contains')}</option>69 </select>70 <div>71 <input72 type="text"73 className="form-control"74 onChange={(e) => this.filterByText = e.target.value}75 onKeyPress={this.handleKeyPress}76 placeholder={T.translate('features.Wrangler.Filter.filter')}77 />78 </div>79 <div className="checkbox form-check">80 <label className="control-label form-check-label">81 <input82 type="checkbox"83 className="form-check-input"84 checked={this.state.filterIgnoreCase}85 onChange={() => this.setState({filterIgnoreCase: !this.state.filterIgnoreCase})}86 />87 {T.translate('features.Wrangler.Filter.ignoreCase')}88 </label>89 </div>90 <br/>91 <div className="text-xs-right">92 <button93 className="btn btn-wrangler"94 onClick={this.onFilter}95 >96 {T.translate('features.Wrangler.Filter.apply')}97 </button>98 </div>99 </div>100 );101 }102 onFilter() {103 if (!this.filterByText) {104 this.setState({filter: null});105 WranglerStore.dispatch({106 type: WranglerActions.setFilter,107 payload: {108 filter: null109 }110 });111 } else {112 let filterObj = {113 column: this.props.column,114 filterBy: this.filterByText,115 filterFunction: this.state.filterFunction,116 filterIgnoreCase: this.state.filterIgnoreCase117 };118 this.setState({119 filter: filterObj120 });121 WranglerStore.dispatch({122 type: WranglerActions.setFilter,123 payload: {124 filter: filterObj125 }126 });127 }128 }129 render() {130 const id = 'wrangler-filter-transform';131 return (132 <div133 className={classnames('transform-item', {134 disabled: !this.props.column,135 expanded: this.state.showFilter136 })}137 onClick={this.onFilterClick}138 >139 <span className="fa fa-font"></span>140 <span141 id={id}142 className="transform-item-text"143 >144 {T.translate('features.Wrangler.Filter.filter')}145 </span>146 {147 !this.props.column ? (148 <Tooltip149 placement="right"150 isOpen={this.state.tooltipOpen}151 toggle={this.toggleTooltip}152 target={id}153 className="wrangler-tooltip"154 delay={{show: 300, hide: 0}}155 tether={{offset: '0 -10px'}}156 >157 {T.translate('features.Wrangler.LeftPanel.selectColumn', {type: 'filter'})}158 </Tooltip>159 ) : null160 }161 {this.renderFilter()}162 </div>163 );164 }165}166Filter.propTypes = {167 column: PropTypes.string...
Using AI Code Generation
1var filterIgnoreCase = require('devicefarmer-stf').filterIgnoreCase;2 {3 "battery": {4 },5 },6 {7 "battery": {8 },9 }10var filter = {11}12var filteredDevices = filterIgnoreCase(devices, filter);13console.log(filteredDevices);14[ { serial: '0123456789ABCDEF',15 battery: { present: true, level: 100, scale: 100 },16 open: true },17 { serial:
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var filterIgnoreCase = stf.filterIgnoreCase;3 {4 "provider": {5 }6 },7 {8 "provider": {9 }10 },11 {12 "provider": {13 }14 },15 {16 "provider": {17 }18 },19 {20 "provider": {21 }22 },23 {24 "provider": {25 }26 },27 {28 "provider": {29 }30 },31 {
Using AI Code Generation
1var utils = require('devicefarmer-stf-utils');2var filteredArray = utils.filterIgnoreCase(['a','b','c'], 'A');3console.log(filteredArray);4var utils = require('devicefarmer-stf-utils');5var filteredArray = utils.filterIgnoreCase(['a','b','c'], 'A');6console.log(filteredArray);7var utils = require('devicefarmer-stf-utils');8var filteredArray = utils.filterIgnoreCase(['a','b','c'], 'A');9console.log(filteredArray);10var utils = require('devicefarmer-stf-utils');11var filteredArray = utils.filterIgnoreCase(['a','b','c'], 'A');12console.log(filteredArray);
Using AI Code Generation
1var db = require('devicefarmer-stf-device-db');2var list = db.filterIgnoreCase('Samsung Galaxy S5');3console.log(list);4var db = require('devicefarmer-stf-device-db');5var list = db.filter('Samsung Galaxy S5');6console.log(list);7var db = require('devicefarmer-stf-device-db');8var list = db.filter('Samsung Galaxy S5');9console.log(list);10var db = require('devicefarmer-stf-device-db');11var list = db.filter('Samsung Galaxy S5');12console.log(list);13var db = require('devicefarmer-stf-device-db');14var list = db.filter('Samsung Galaxy S5');15console.log(list);16var db = require('devicefarmer-stf-device-db');17var list = db.filter('Samsung Galaxy S5');18console.log(list);19var db = require('devicefarmer-stf-device-db');20var list = db.filter('Samsung Galaxy S5');21console.log(list);22var db = require('devicefarmer-stf-device-db');23var list = db.filter('Samsung Galaxy S5');24console.log(list);25var db = require('devicefarmer-stf-device-db');26var list = db.filter('Samsung Galaxy S5');27console.log(list);28var db = require('devicefarmer-stf-device-db');29var list = db.filter('Samsung Galaxy S5');30console.log(list);31var db = require('
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf-client');2var client = new devicefarmer.Client();3client.getDevices().then(function(devices){4devices = client.filterIgnoreCase(devices, 'model', 'Nexus 5');5console.log(devices);6});7getDevices() method8var devicefarmer = require('devicefarmer-stf-client');9var client = new devicefarmer.Client();10client.getDevices().then(function(devices){11console.log(devices);12});13getDevice() method14The getDevice() method is used to get the details of a device in the STF server. The method
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!!