Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- createSelectedDevicesDS(selectedDevices) {
- const selectedDevicesDS = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
- //this.selectedDevicesList = selectedDevicesDS.cloneWithRows(selectedDevices);
- let mapSelectedDevices = selectedDevices.map((item, i) => ({ key: `${i}`, device: item }));
- this.setState({ selectedDevicesListDS: selectedDevicesDS.cloneWithRows(mapSelectedDevices), selectedDevices: mapSelectedDevices })
- }
- renderRowSelectedDevices = (data, secId, rowId, rowMap) => {
- let device = data.device;
- let widthPercentage = Dimensions.get('window').width - 40;
- if (device.bloqueado)
- widthPercentage -= 16;
- let widthPercentageScale = widthPercentage / 100;
- let infoLine = device.callerId;
- let infoLineFontSize = 22;
- if (this.props.fieldShow == 'iccid') {
- infoLineFontSize = 16;
- infoLine = device.iccid;
- } else if (this.props.fieldShow == 'cliente') {
- if (device.descricao.cliente) {
- infoLine = device.descricao.cliente;
- }
- }
- let fillWidth = device.consumoPerc * widthPercentageScale;
- let bgColorPercentage = AppConstants.primaryColor;
- let bgColorLine = AppConstants.secondaryColor;
- let textPercentage = `${device.consumoPerc}%`;
- let textPercentageFontSize = 22;
- let ultimaConexao = '';
- let lastConnection = '';
- currentDate = moment()
- if (device.ultimaConexao !== '-') {
- ultimaConexao = moment(device.ultimaConexao);
- lastConnection = currentDate - ultimaConexao;
- lastConnection = lastConnection / 60000;
- if (lastConnection < 60) {
- lastConnection = `${Math.ceil(lastConnection)} min`;
- } else {
- lastConnection = lastConnection / 60;
- if (lastConnection < 24) {
- lastConnection = `${Math.ceil(lastConnection)} h`;
- } else {
- lastConnection = lastConnection / 24;
- if (lastConnection < 2 && (currentDate.date() - ultimaConexao.date()) == 1) {
- lastConnection = `Ontem às ${ultimaConexao.format("HH:mm")}`;
- } else if (lastConnection < 4) {
- lastConnection = `${AppConstants.daysOfWeek[ultimaConexao.day()]} às ${ultimaConexao.format("HH:mm")}`;
- } else {
- lastConnection = `${ultimaConexao.format('D')} de ${AppConstants.months[ultimaConexao.month()]}`;
- }
- }
- }
- } else if (!device.emEstoque) {
- lastConnection = 'Online'
- }
- if (device.ativo) {
- bgColorLine = AppConstants.primaryColor;
- }
- if (device.altoTrafego) {
- bgColorPercentage = AppConstants.secondaryColor;
- bgColorLine = AppConstants.secondaryColor;
- } else {
- bgColorPercentage = AppConstants.primaryColor;
- bgColorLine = AppConstants.primaryColor;
- }
- // let name = 'circle-o';
- let name = 'circle';
- let bgIcon = AppConstants.secondaryColor;
- let bgArrow = AppConstants.greyColor;
- if (device.statusAtivo == 'Ativo') {
- bgIcon = '#55CF19';
- }
- if (device.emEstoque) {
- bgIcon = AppConstants.backgroundColor;
- bgColorPercentage = AppConstants.backgroundColor;
- bgArrow = AppConstants.backgroundColor;
- textPercentage = 'Estoque';
- name = 'circle-o';
- textPercentageFontSize = 14;
- fillWidth = 0;
- }
- if (device.bloqueado) {
- fillWidth = 0;
- bgColorPercentage = AppConstants.backgroundColor;
- bgIcon = AppConstants.backgroundColor;
- bgArrow = AppConstants.backgroundColor;
- name = 'lock';
- }
- <SwipeListView
- style={{ backgroundColor: '#FFFFFF', flex: 1, marginBottom: 2 }}
- dataSource={this.state.selectedDevicesListDS}
- renderRow={this.renderRowSelectedDevices}
- onRowDidOpen={this.onRowDidOpen}
- />
- </View>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement