fixed update user rights button
This commit is contained in:
parent
9cc7462ad2
commit
c617fff315
@ -23,7 +23,7 @@ data class UserDTO (
|
|||||||
@SerialName("roles")
|
@SerialName("roles")
|
||||||
val roles: List<AuthorityDTO>,
|
val roles: List<AuthorityDTO>,
|
||||||
@SerialName("acsblocked")
|
@SerialName("acsblocked")
|
||||||
val isACSBlocked: Boolean
|
var isACSBlocked: Boolean
|
||||||
// @SerialName("lastVisit")
|
// @SerialName("lastVisit")
|
||||||
// val lastVisit: String,
|
// val lastVisit: String,
|
||||||
) : java.io.Serializable
|
) : java.io.Serializable
|
@ -15,6 +15,7 @@ import com.displaynone.acss.components.acs.models.visit.VisitAdapter
|
|||||||
import com.displaynone.acss.components.auth.models.user.UserServiceST
|
import com.displaynone.acss.components.auth.models.user.UserServiceST
|
||||||
import com.displaynone.acss.components.auth.models.user.repository.dto.UserDTO
|
import com.displaynone.acss.components.auth.models.user.repository.dto.UserDTO
|
||||||
import com.displaynone.acss.databinding.FragmentProfileBinding
|
import com.displaynone.acss.databinding.FragmentProfileBinding
|
||||||
|
import com.displaynone.acss.ui.init.InitFragmentViewModel
|
||||||
import com.displaynone.acss.ui.profile.ProfileViewModel.Action
|
import com.displaynone.acss.ui.profile.ProfileViewModel.Action
|
||||||
import com.displaynone.acss.ui.scan.QrScanDestination
|
import com.displaynone.acss.ui.scan.QrScanDestination
|
||||||
import com.displaynone.acss.util.collectWithLifecycle
|
import com.displaynone.acss.util.collectWithLifecycle
|
||||||
@ -92,19 +93,25 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) {
|
|||||||
binding.position.text = userDTO.position
|
binding.position.text = userDTO.position
|
||||||
setAvatar(userDTO.photo)
|
setAvatar(userDTO.photo)
|
||||||
}
|
}
|
||||||
|
private fun updateRights(isACSBlocked: Boolean){
|
||||||
|
binding.changeRights.text = if(isACSBlocked) "Разблокировать пользователя" else "Заблокировать пользователя"
|
||||||
|
}
|
||||||
|
|
||||||
private fun showData(userDTO: UserDTO) {
|
private fun showData(userDTO: UserDTO) {
|
||||||
binding.fio.text = userDTO.name
|
binding.fio.text = userDTO.name
|
||||||
binding.position.text = userDTO.position
|
binding.position.text = userDTO.position
|
||||||
binding.changeRights.text = if(userDTO.isACSBlocked) "Разблокировать пользователя" else "Заблокировать пользователя"
|
updateRights(userDTO.isACSBlocked)
|
||||||
viewModel.setLogin(login1 = userDTO.login)
|
viewModel.setLogin(login1 = userDTO.login)
|
||||||
binding.changeRights.setOnClickListener {
|
binding.changeRights.setOnClickListener {
|
||||||
viewModel.changeRights(userDTO.login, !userDTO.isACSBlocked)
|
viewModel.changeRights(userDTO.login, !userDTO.isACSBlocked)
|
||||||
}
|
}
|
||||||
|
viewModel.state.collectWithLifecycle(this){ state ->
|
||||||
|
if (state is ProfileViewModel.State.Change){
|
||||||
|
updateRights(state.item)
|
||||||
|
userDTO.isACSBlocked = state.item
|
||||||
|
}
|
||||||
|
}
|
||||||
Log.d("ProfileFragment", userDTO.login)
|
Log.d("ProfileFragment", userDTO.login)
|
||||||
|
|
||||||
// binding.lastEntry.text = userDTO.lastVisit
|
|
||||||
|
|
||||||
setAvatar(userDTO.photo)
|
setAvatar(userDTO.photo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ class ProfileViewModel(): ViewModel() {
|
|||||||
Log.d("Pvm", data.login)
|
Log.d("Pvm", data.login)
|
||||||
},
|
},
|
||||||
onFailure = { error ->
|
onFailure = { error ->
|
||||||
error.message?.let { error(it) }
|
error.message?.let { error(it) } //FIXME()
|
||||||
Log.e("ProfileViewModel", error.message.toString())
|
Log.e("ProfileViewModel", error.message.toString())
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -72,7 +72,7 @@ class ProfileViewModel(): ViewModel() {
|
|||||||
UserServiceST.getInstance().changeRights(login, isACSBlocked).fold(
|
UserServiceST.getInstance().changeRights(login, isACSBlocked).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
Log.d("ProfileViewModel", "changed rights")
|
Log.d("ProfileViewModel", "changed rights")
|
||||||
// _state.emit(State.Change(isACSBlocked))
|
_state.emit(State.Change(isACSBlocked))
|
||||||
},
|
},
|
||||||
onFailure = { error ->
|
onFailure = { error ->
|
||||||
Log.d("ProfileViewModel", "failed to change rights ${error.message}")
|
Log.d("ProfileViewModel", "failed to change rights ${error.message}")
|
||||||
@ -98,7 +98,7 @@ class ProfileViewModel(): ViewModel() {
|
|||||||
) : State
|
) : State
|
||||||
data class Change(
|
data class Change(
|
||||||
val item: Boolean
|
val item: Boolean
|
||||||
)
|
) : State
|
||||||
}
|
}
|
||||||
sealed interface Action {
|
sealed interface Action {
|
||||||
data object GoToAuth: Action
|
data object GoToAuth: Action
|
||||||
|
Loading…
x
Reference in New Issue
Block a user