Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.52 KB | None | 0 0
  1. class TarefasConcluidas extends Component {
  2.  
  3. componentWillMount() {
  4. this.props.tarefasUsuarioFetchConcluidas();
  5. this.criaFonteDeDados( this.props.tarefas )
  6. // this.setState({ showAddTask: false })
  7.  
  8. }
  9.  
  10. componentWillReceiveProps(nextProps){
  11.  
  12. this.criaFonteDeDados(nextProps.tarefas)
  13. }
  14.  
  15. criaFonteDeDados( tarefas ){
  16. const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 })
  17.  
  18. this.fonteDeDados = ds.cloneWithRows(tarefas)
  19. }
  20.  
  21. state = {
  22. showExcTask: false
  23. }
  24.  
  25. fechamodal = () => {
  26. this.setState({ showExcTask: false})
  27. }
  28.  
  29. _excluirTarefaConcluida (uid) {
  30. const IdTarefa = uid;
  31. this.props.ExcluirTarefaConcluida({IdTarefa});
  32. }
  33.  
  34. atualizaId(id){
  35. this.props.idTarefa = this.props.modificaUID(id)
  36. }
  37.  
  38. obsTarefa(tarefas){
  39. if(tarefas.trim()){
  40. return(
  41.  
  42. <Text style={styles.obs}>{tarefas}</Text>
  43. )
  44. }else{
  45. return(
  46. <Text style={styles.obs}>Sem observações...</Text>
  47. )
  48. }
  49. }
  50.  
  51. _reiniciaTarefa (idTarefa, dataInicio, desc, grau, user, obs, dias, horas, minutos, segundos, priori) {
  52.  
  53. const uid = idTarefa;
  54. const dataInicioTarefa = dataInicio;
  55. const descricao = desc;
  56. const grauDaTarefa = grau;
  57. const nomeUsuario = user;
  58. const observacoes = obs;
  59. const qtdDias = dias;
  60. const qtdHoras = horas;
  61. const qtdMinutos = minutos;
  62. const qtdSegundos = segundos;
  63. const tarefaPrioritaria = priori;
  64.  
  65. this.props.reiniciarTarefa({uid, dataInicioTarefa, descricao, grauDaTarefa, nomeUsuario, observacoes, qtdDias, qtdHoras, qtdMinutos, qtdSegundos, tarefaPrioritaria})
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72. tempoGasto(qtdDias, qtdHoras,qtdMinutos, qtdSegundos){
  73.  
  74.  
  75. if(qtdDias == '0' && qtdHoras== '0' && qtdMinutos== '0' && qtdSegundos != '0'){
  76. return(
  77. <Text style={{ color: '#555', fontSize: 14, marginLeft: 10, marginBottom: 5, marginBottom: 5}}>Tempo gasto: {qtdSegundos} segundos.</Text>
  78. )
  79. }else if(qtdDias== '0' && qtdHoras== '0' && qtdMinutos != '0'){
  80. return(
  81. <Text style={{ color: '#555', fontSize: 14, marginLeft: 10, marginBottom: 5, marginBottom: 5}}>Tempo gasto: {qtdMinutos} minutos e {qtdSegundos} segundos.</Text>
  82. )
  83. }else if(qtdDias== '0' && qtdHoras != '0'){
  84. return(
  85. <Text style={{ color: '#555', fontSize: 14, marginLeft: 10, marginBottom: 5, marginBottom: 5}}>Tempo gasto: {qtdHoras} horas, {qtdMinutos} minutos e {qtdSegundos} segundos.</Text>
  86. )
  87. }else if(qtdDias !='0'){
  88. return(
  89. <Text style={{ color: '#555', fontSize: 14, marginLeft: 10, marginBottom: 5, marginBottom: 5}}>Tempo gasto: {qtdDias} dias, {qtdHoras} horas, {qtdMinutos} minutos e {qtdSegundos} segundos.</Text>
  90. )
  91. }
  92.  
  93.  
  94. }
  95.  
  96. renderRow(tarefas){
  97. if(tarefas.tarefaPrioritaria == 'Não'){
  98. return (
  99. <View style={{ marginTop: 2}}>
  100. <View style={styles.container2}>
  101. <View style={styles.mantem}>
  102. <Text style={styles.desc}>{tarefas.descricao}</Text>
  103. <Text style={styles.obs}>{this.obsTarefa(tarefas.observacoes)}</Text>
  104. <Text style={styles.inicio}>Iniciada em: {moment(tarefas.dataInicioTarefa).locale('pt-br').format('ddd, D [de] MMMM HH:mm')} </Text>
  105. <Text style={styles.inicio}>Finalizada em: {moment(tarefas.dataTerminoTarefa).locale('pt-br').format('ddd, D [de] MMMM HH:mm')}</Text>
  106. {this.tempoGasto(tarefas.qtdDias,tarefas.qtdHoras, tarefas.qtdMinutos, tarefas.qtdSegundos)}
  107. </View>
  108. <View style={ { marginRight: 10}}>
  109. <TouchableOpacity style={styles.manter} onPress={() => this._reiniciaTarefa(tarefas.uid,
  110. tarefas.dataInicioTarefa,
  111. tarefas.descricao,
  112. tarefas.grauDaTarefa,
  113. tarefas.nomeUsuario,
  114. tarefas.observacoes,
  115. tarefas.qtdDias,
  116. tarefas.qtdHoras,
  117. tarefas.qtdMinutos,
  118. tarefas.qtdSegundos,
  119. tarefas.tarefaPrioritaria)}>
  120. <Icon name='undo' size={25} color='green'/>
  121. <Text style={ { marginTop: 3, marginLeft: 2}}>Reiniciar</Text>
  122. </TouchableOpacity>
  123. <TouchableOpacity style={styles.manter2} onPress={() => { this.setState({ showExcTask: true }), this.atualizaId(tarefas.uid)}}>
  124. <Icon name='trash' size={25} color='red'/>
  125. <Text style={ { marginTop: 5, marginLeft: 2}}>Excluir</Text>
  126. </TouchableOpacity>
  127. </View>
  128. </View>
  129. </View>
  130. )
  131. }else{
  132. return (
  133. <View style={{ marginTop: 2}}>
  134. <Text style={styles.tarefaPri}>Tarefa prioritária.</Text>
  135. <View style={styles.container2}>
  136. <View style={styles.mantem}>
  137. <Text style={styles.desc}>{tarefas.descricao}</Text>
  138. <Text style={styles.obs}>{this.obsTarefa(tarefas.observacoes)}</Text>
  139. <Text style={styles.inicio}>Iniciada em: {moment(tarefas.dataInicioTarefa).locale('pt-br').format('ddd, D [de] MMMM HH:mm')} </Text>
  140. <Text style={styles.inicio}>Finalizada em: {moment(tarefas.dataTerminoTarefa).locale('pt-br').format('ddd, D [de] MMMM HH:mm')}</Text>
  141. {this.tempoGasto(tarefas.qtdDias,tarefas.qtdHoras, tarefas.qtdMinutos, tarefas.qtdSegundos)}
  142. </View>
  143. <View style={ { marginRight: 10}}>
  144. <TouchableOpacity style={styles.manter} onPress={() => this._reiniciaTarefa(tarefas.uid,
  145. tarefas.dataInicioTarefa,
  146. tarefas.descricao,
  147. tarefas.grauDaTarefa,
  148. tarefas.nomeUsuario,
  149. tarefas.observacoes,
  150. tarefas.qtdDias,
  151. tarefas.qtdHoras,
  152. tarefas.qtdMinutos,
  153. tarefas.qtdSegundos,
  154. tarefas.tarefaPrioritaria)}>
  155. <Icon name='undo' size={25} color='green'/>
  156. <Text style={ { marginTop: 3, marginLeft: 2}}>Reiniciar</Text>
  157. </TouchableOpacity>
  158. <TouchableOpacity style={styles.manter2} onPress={() => { this.setState({ showExcTask: true }), this.atualizaId(tarefas.uid)}}>
  159. <Icon name='trash' size={25} color='red'/>
  160. <Text style={ { marginTop: 5, marginLeft: 2}}>Excluir</Text>
  161. </TouchableOpacity>
  162. </View>
  163. </View>
  164. </View>
  165. )
  166. }
  167.  
  168. }
  169.  
  170.  
  171. render() {
  172. //const options = { email: this.props.email}
  173.  
  174. return (
  175. <View style = {styles.container}>
  176. <ModalExcluirTarefaConcluida isVisible={this.state.showExcTask}
  177. onSave={this.fechamodal}
  178. onCancel={() => this.setState({showExcTask: false})} />
  179. <View style = {styles.background}>
  180. <View style = {styles.botaoMenu}>
  181. <TouchableOpacity onPress={() => this.props.navigation.openDrawer()}>
  182. <Icon name='bars' size={25} color='white'/>
  183. </TouchableOpacity>
  184. </View>
  185. <View style={styles.titleBar}>
  186. <Text style={styles.title}>Tarefas Concluidas.</Text>
  187. <Text style={styles.subtitle}>
  188.  
  189. {moment().locale('pt-br').format('ddd, D [de] MMMM HH:mm')}
  190. </Text>
  191.  
  192. </View>
  193. </View>
  194. <View style={styles.taskContainer}>
  195. <ListView
  196. dataSource = {this.fonteDeDados}
  197. renderRow = {data => this.renderRow(data)}
  198. enableEmptySections={true}
  199. />
  200. </View>
  201. </View>
  202. )
  203. }
  204. }
  205.  
  206. const styles = StyleSheet.create({
  207. container: {
  208. flex: 1,
  209. },
  210. tarefaPri: {
  211. textAlign: 'center',
  212. fontSize: 18,
  213. color: '#FF6347',
  214. marginTop: 4
  215. },
  216. background: {
  217. flex: 2.5,
  218. //width: '100%',
  219. backgroundColor: '#084d6e'
  220. },
  221. manter: {
  222. marginTop: 30,
  223. flexDirection: 'row'
  224. },
  225. manter2: {
  226. flexDirection: 'row',
  227. marginTop: 5,
  228. marginBottom: 5
  229. },
  230. container2: {
  231. flexDirection: 'row',
  232. borderBottomWidth: 1,
  233. borderColor: '#AAA',
  234. justifyContent: 'space-between',
  235.  
  236. },
  237. titleBar: {
  238. flex: 1,
  239. justifyContent: 'flex-end'
  240. },
  241. title: {
  242. color: "#FFF",
  243. fontSize: 30,
  244. marginLeft: 20,
  245. marginBottom: 10,
  246. marginTop: 40
  247. },
  248. subtitle: {
  249. color: "#FFF",
  250. fontSize: 20,
  251. marginLeft: 22,
  252. marginBottom: 30
  253. },
  254. taskContainer: {
  255. flex: 5,
  256.  
  257. },
  258. botaoMenu: {
  259. marginLeft: 20,
  260. marginTop: 10
  261.  
  262. },
  263. desc: {
  264. color: '#555',
  265. fontSize: 20,
  266. marginLeft: 10
  267. },
  268. obs: {
  269. color: '#555',
  270. fontSize: 16,
  271. marginLeft: 10
  272. },
  273. inicio: {
  274. color: '#555',
  275. fontSize: 14,
  276. marginLeft: 10
  277. },
  278. button: {
  279. backgroundColor: '#080',
  280. marginTop: 5,
  281. padding: 5,
  282. color: '#fff',
  283.  
  284.  
  285. },
  286. btnExcluir: {
  287. backgroundColor: '#ff4040',
  288. marginTop: 5,
  289. padding: 5,
  290. color: '#fff',
  291. },
  292. mantem: {
  293. width: '75%',
  294. },
  295.  
  296. })
  297.  
  298.  
  299. const mapStateToProps = state => {
  300. const tarefas = _.map(state.ListaTarefasConcluidasReducer, (val, uid) => {
  301. return { ...val, uid }
  302. })
  303. return{
  304. idTarefa: state.tarefasReducer.uid,
  305. tarefas: tarefas.reverse()
  306.  
  307. }
  308.  
  309. }
  310.  
  311. export default connect(mapStateToProps, {tarefasUsuarioFetchConcluidas, ExcluirTarefaConcluida,reiniciarTarefa, modificaUID})(TarefasConcluidas)
  312.  
  313. //export default Inicio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement