Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. createSelectedDevicesDS(selectedDevices) {
  2. const selectedDevicesDS = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
  3. //this.selectedDevicesList = selectedDevicesDS.cloneWithRows(selectedDevices);
  4. let mapSelectedDevices = selectedDevices.map((item, i) => ({ key: `${i}`, device: item }));
  5. this.setState({ selectedDevicesListDS: selectedDevicesDS.cloneWithRows(mapSelectedDevices), selectedDevices: mapSelectedDevices })
  6. }
  7.  
  8.  
  9. renderRowSelectedDevices = (data, secId, rowId, rowMap) => {
  10. let device = data.device;
  11.  
  12. let widthPercentage = Dimensions.get('window').width - 40;
  13. if (device.bloqueado)
  14. widthPercentage -= 16;
  15.  
  16. let widthPercentageScale = widthPercentage / 100;
  17.  
  18. let infoLine = device.callerId;
  19. let infoLineFontSize = 22;
  20. if (this.props.fieldShow == 'iccid') {
  21. infoLineFontSize = 16;
  22. infoLine = device.iccid;
  23. } else if (this.props.fieldShow == 'cliente') {
  24. if (device.descricao.cliente) {
  25. infoLine = device.descricao.cliente;
  26. }
  27. }
  28.  
  29. let fillWidth = device.consumoPerc * widthPercentageScale;
  30. let bgColorPercentage = AppConstants.primaryColor;
  31. let bgColorLine = AppConstants.secondaryColor;
  32. let textPercentage = `${device.consumoPerc}%`;
  33. let textPercentageFontSize = 22;
  34. let ultimaConexao = '';
  35. let lastConnection = '';
  36. currentDate = moment()
  37. if (device.ultimaConexao !== '-') {
  38. ultimaConexao = moment(device.ultimaConexao);
  39. lastConnection = currentDate - ultimaConexao;
  40. lastConnection = lastConnection / 60000;
  41. if (lastConnection < 60) {
  42. lastConnection = `${Math.ceil(lastConnection)} min`;
  43. } else {
  44. lastConnection = lastConnection / 60;
  45. if (lastConnection < 24) {
  46. lastConnection = `${Math.ceil(lastConnection)} h`;
  47. } else {
  48. lastConnection = lastConnection / 24;
  49. if (lastConnection < 2 && (currentDate.date() - ultimaConexao.date()) == 1) {
  50. lastConnection = `Ontem às ${ultimaConexao.format("HH:mm")}`;
  51. } else if (lastConnection < 4) {
  52. lastConnection = `${AppConstants.daysOfWeek[ultimaConexao.day()]} às ${ultimaConexao.format("HH:mm")}`;
  53. } else {
  54. lastConnection = `${ultimaConexao.format('D')} de ${AppConstants.months[ultimaConexao.month()]}`;
  55. }
  56. }
  57. }
  58. } else if (!device.emEstoque) {
  59. lastConnection = 'Online'
  60. }
  61.  
  62. if (device.ativo) {
  63. bgColorLine = AppConstants.primaryColor;
  64. }
  65.  
  66. if (device.altoTrafego) {
  67. bgColorPercentage = AppConstants.secondaryColor;
  68. bgColorLine = AppConstants.secondaryColor;
  69. } else {
  70. bgColorPercentage = AppConstants.primaryColor;
  71. bgColorLine = AppConstants.primaryColor;
  72. }
  73. // let name = 'circle-o';
  74. let name = 'circle';
  75. let bgIcon = AppConstants.secondaryColor;
  76. let bgArrow = AppConstants.greyColor;
  77. if (device.statusAtivo == 'Ativo') {
  78. bgIcon = '#55CF19';
  79. }
  80. if (device.emEstoque) {
  81. bgIcon = AppConstants.backgroundColor;
  82. bgColorPercentage = AppConstants.backgroundColor;
  83. bgArrow = AppConstants.backgroundColor;
  84. textPercentage = 'Estoque';
  85. name = 'circle-o';
  86. textPercentageFontSize = 14;
  87. fillWidth = 0;
  88. }
  89. if (device.bloqueado) {
  90. fillWidth = 0;
  91. bgColorPercentage = AppConstants.backgroundColor;
  92. bgIcon = AppConstants.backgroundColor;
  93. bgArrow = AppConstants.backgroundColor;
  94. name = 'lock';
  95. }
  96.  
  97. <SwipeListView
  98. style={{ backgroundColor: '#FFFFFF', flex: 1, marginBottom: 2 }}
  99. dataSource={this.state.selectedDevicesListDS}
  100. renderRow={this.renderRowSelectedDevices}
  101. onRowDidOpen={this.onRowDidOpen}
  102. />
  103. </View>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement