Skip to content

Commit

Permalink
revisoes realizadas
Browse files Browse the repository at this point in the history
  • Loading branch information
urielfcampos committed May 13, 2019
1 parent 5687227 commit 8c569d5
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 18 deletions.
31 changes: 25 additions & 6 deletions components/searchInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<b-table
:striped="isStriped"
:hoverable="isHoverabble"
:data="filteredList"
:data="students"
:selected.sync="selectedStudent"
:columns="columns"
focusable
Expand All @@ -38,12 +38,10 @@
</template>

<script>
import { Toast } from 'buefy/dist/components/toast'
import studentComboBox from '../components/studentComboBox'
import debounce from '../shared/debounce.js'
export default {
name: 'SearchInput',
// props: ['title', 'students', 'thead'],
components: {
studentComboBox
},
Expand Down Expand Up @@ -76,7 +74,8 @@ export default {
field: 'email',
label: 'Email'
}
]
],
filterOrderBy: false
}
},
Expand All @@ -96,11 +95,31 @@ export default {
mounted() {
if (this.students.length < 1) {
Toast.open({
this.$toast.open({
message: 'Não há alunos ativos neste curso',
type: 'is-danger'
})
}
},
methods: {
getStudentsFilters: debounce(() => {
this.$axios
.get('/api/students/', {
params: {
course: this.courseTag,
isActive: 1
}
})
.then(res => {
this.students = res.data
})
.catch(() => {
this.$toast.open({
message: 'Falha ao carregar a lista de alunos.',
type: 'is-danger'
})
})
}, 500)
}
}
</script>
Expand Down
4 changes: 1 addition & 3 deletions layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ export default {
currrentUser: 'auth/currentUser'
}),
courseNameUppercase() {
if (this.courseTag) {
return this.courseTag.toUpperCase()
} else return false
return this.courseTag && this.courseTag.toUpperCase()
}
},
methods: {
Expand Down
2 changes: 0 additions & 2 deletions middleware/course.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { Toast } from 'buefy/dist/components/toast'
export default function({ store, redirect }) {
if (!store.state.courseTag) {
Toast.open('Selecione um Curso')
// eslint-disable-next-line no-console
console.log('trying')
redirect('/')
}
}
16 changes: 10 additions & 6 deletions pages/activeStudents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<script>
import { mapState } from 'vuex'
import SearchInput from '~/components/searchInput'
import '@nuxtjs/axios'
export default {
name: 'Active',
Expand All @@ -34,9 +33,12 @@ export default {
methods: {
async getStudents() {
try {
this.students = await this.$axios.$get(
`/api/students/?course=${this.courseTag}&isActive=1`
)
this.students = await this.$axios.$get('/api/students/', {
params: {
course: this.courseTag,
isActive: 1
}
})
} catch (e) {
this.openErrorNotification(e.response.data.code)
}
Expand All @@ -51,12 +53,14 @@ export default {
return 'Arquivo csv com numero invalido de colunas'
case 'IMPORT_CSV_INVALID_FILE':
return 'Por favor selecione um arquivo do tipo csv'
default:
return 'Ocorreu um erro'
}
},
openErrorNotification(errorMessage) {
openErrorNotification(errorCode) {
this.$notification.open({
duration: 5000,
message: errorMessage,
message: this.errorMessage(errorCode),
position: 'is-top',
type: 'is-danger',
hasIcon: true
Expand Down
6 changes: 5 additions & 1 deletion pages/allStudents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export default {
},
created() {
this.$axios
.get(`/api/students/?course=${this.courseTag}`)
.get('/api/students/', {
params: {
course: this.courseTag
}
})
.then(res => {
this.students = res.data
})
Expand Down
27 changes: 27 additions & 0 deletions shared/debounce.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Credit David Walsh (https://davidwalsh.name/javascript-debounce-function)

// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
export default function debounce(func, wait, immediate) {
let timeout

return function executedFunction() {
const context = this
const args = arguments

const later = function() {
timeout = null
if (!immediate) func.apply(context, args)
}

const callNow = immediate && !timeout

clearTimeout(timeout)

timeout = setTimeout(later, wait)

if (callNow) func.apply(context, args)
}
}

0 comments on commit 8c569d5

Please sign in to comment.