надо перенести отмену на страницу с записью
This commit is contained in:
parent
d3ea61ad03
commit
ea3b827b55
@ -44,10 +44,12 @@ import androidx.lifecycle.viewmodel.compose.viewModel
|
|||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.paging.compose.collectAsLazyPagingItems
|
import androidx.paging.compose.collectAsLazyPagingItems
|
||||||
import com.example.myapplication.Graph.AuthScreen
|
import com.example.myapplication.Graph.AuthScreen
|
||||||
|
import com.example.myapplication.Graph.BottomBarScreen
|
||||||
import com.example.myapplication.dataBase.model.RoleEnum
|
import com.example.myapplication.dataBase.model.RoleEnum
|
||||||
import com.example.myapplication.ui.AppViewModelProvider
|
import com.example.myapplication.ui.AppViewModelProvider
|
||||||
import com.example.myapplication.ui.edit.DayDropDownViewModel
|
import com.example.myapplication.ui.edit.DayDropDownViewModel
|
||||||
import com.example.myapplication.ui.edit.DirectionDropDownViewModel
|
import com.example.myapplication.ui.edit.DirectionDropDownViewModel
|
||||||
|
import com.example.myapplication.ui.edit.LessonEditViewModel
|
||||||
import com.example.myapplication.ui.lesson.LessonListViewModel
|
import com.example.myapplication.ui.lesson.LessonListViewModel
|
||||||
import com.example.myapplication.ui.user.CurrentUserViewModel
|
import com.example.myapplication.ui.user.CurrentUserViewModel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -512,7 +514,7 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "Отменить запись",
|
text = "К записи",
|
||||||
color = Color.White,
|
color = Color.White,
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
style = TextStyle(
|
style = TextStyle(
|
||||||
@ -527,12 +529,14 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
|
|||||||
.clickable(
|
.clickable(
|
||||||
enabled = getUser?.lessonId != null,
|
enabled = getUser?.lessonId != null,
|
||||||
onClick = {
|
onClick = {
|
||||||
getUser?.lessonId = null
|
// getUser?.lessonId = null
|
||||||
coroutineScope.launch {
|
// coroutineScope.launch {
|
||||||
getUser?.let {
|
// getUser?.let {
|
||||||
currentUserViewModel.updateUser(it)
|
// currentUserViewModel.updateUser(it)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
val route = BottomBarScreen.LessonRecord.route.replace("{id}", lessonId.toString())
|
||||||
|
navController.navigate(route)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -544,3 +548,4 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,6 +51,33 @@ class LessonEditViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun updateRecords() {
|
||||||
|
if (validateInput()) {
|
||||||
|
if (lessonUid > 0) {
|
||||||
|
val updatedCountRecord = lessonUiState.lessonDetails.countRecord - 1
|
||||||
|
lessonUiState = lessonUiState.copy(
|
||||||
|
lessonDetails = lessonUiState.lessonDetails.copy(countRecord = updatedCountRecord)
|
||||||
|
)
|
||||||
|
lessonRepository.updateLesson(lessonUiState.lessonDetails.toLesson(lessonUid))
|
||||||
|
} else {
|
||||||
|
lessonRepository.insertLesson(lessonUiState.lessonDetails.toLesson())
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun updateRecordsForCancel() {
|
||||||
|
if (validateInput()) {
|
||||||
|
if (lessonUid > 0) {
|
||||||
|
val updatedCountRecord = lessonUiState.lessonDetails.countRecord + 1
|
||||||
|
lessonUiState = lessonUiState.copy(
|
||||||
|
lessonDetails = lessonUiState.lessonDetails.copy(countRecord = updatedCountRecord)
|
||||||
|
)
|
||||||
|
lessonRepository.updateLesson(lessonUiState.lessonDetails.toLesson(lessonUid))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun validateInput(uiState: LessonDetails = lessonUiState.lessonDetails): Boolean {
|
private fun validateInput(uiState: LessonDetails = lessonUiState.lessonDetails): Boolean {
|
||||||
return with(uiState) {
|
return with(uiState) {
|
||||||
teacher.isNotBlank()
|
teacher.isNotBlank()
|
||||||
|
@ -36,25 +36,28 @@ fun LessonRecord(
|
|||||||
directionViewModel.setCurrentDirection(viewModel.lessonUiState.lessonDetails.directionId)
|
directionViewModel.setCurrentDirection(viewModel.lessonUiState.lessonDetails.directionId)
|
||||||
val getUser by remember { mutableStateOf(currentUserViewModel.user) }
|
val getUser by remember { mutableStateOf(currentUserViewModel.user) }
|
||||||
Log.d("getUserLesson", "gU: $getUser")
|
Log.d("getUserLesson", "gU: $getUser")
|
||||||
|
val lessonCurId = viewModel.getUidLesson()
|
||||||
LessonRecord(
|
LessonRecord(
|
||||||
lessonUiState = viewModel.lessonUiState,
|
lessonUiState = viewModel.lessonUiState,
|
||||||
directionUiState = directionViewModel.directionUiState,
|
directionUiState = directionViewModel.directionUiState,
|
||||||
|
enabled = getUser?.lessonId != lessonCurId,
|
||||||
onClick = {
|
onClick = {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
val lessonCurId = viewModel.getUidLesson()
|
|
||||||
Log.d("LessonBefore", "LB: ${getUser?.lessonId}")
|
Log.d("LessonBefore", "LB: ${getUser?.lessonId}")
|
||||||
|
if (lessonCurId != getUser?.lessonId) {
|
||||||
getUser?.let {
|
getUser?.let {
|
||||||
it.lessonId = lessonCurId
|
it.lessonId = lessonCurId
|
||||||
Log.d("LessonAfter", "LA: ${getUser?.lessonId}")
|
Log.d("LessonAfter", "LA: ${getUser?.lessonId}")
|
||||||
currentUserViewModel.updateUser(it)
|
currentUserViewModel.updateUser(it)
|
||||||
Log.d("UserAfter", "UA: $getUser")
|
Log.d("UserAfter", "UA: $getUser")
|
||||||
|
}
|
||||||
|
viewModel.updateRecords()
|
||||||
}
|
}
|
||||||
navController.popBackStack()
|
navController.popBackStack()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
},
|
||||||
|
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,6 +66,7 @@ fun LessonRecord(
|
|||||||
private fun LessonRecord(
|
private fun LessonRecord(
|
||||||
lessonUiState: LessonUiState,
|
lessonUiState: LessonUiState,
|
||||||
directionUiState: DirectionUiState,
|
directionUiState: DirectionUiState,
|
||||||
|
enabled: Boolean,
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
onUpdate: (LessonDetails) -> Unit
|
onUpdate: (LessonDetails) -> Unit
|
||||||
) {
|
) {
|
||||||
@ -113,6 +117,7 @@ private fun LessonRecord(
|
|||||||
)
|
)
|
||||||
Button(
|
Button(
|
||||||
onClick = onClick,
|
onClick = onClick,
|
||||||
|
enabled = enabled,
|
||||||
shape = MaterialTheme.shapes.small,
|
shape = MaterialTheme.shapes.small,
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
|
@ -38,35 +38,3 @@ class LessonListViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//class LessonListViewModel(private val lessonRepository: LessonRepository): ViewModel() {
|
|
||||||
// var teacher = mutableStateOf("")
|
|
||||||
// val classNumber = mutableStateOf("")
|
|
||||||
// val time = mutableStateOf("")
|
|
||||||
// val directionId = mutableStateOf("")
|
|
||||||
// val dayOfWeekId = mutableStateOf("")
|
|
||||||
// val LessonList = lessonRepository.call().cachedIn(viewModelScope)
|
|
||||||
// var lesson: Lesson? = null
|
|
||||||
//
|
|
||||||
// fun insert() = viewModelScope.launch {
|
|
||||||
// val lesson = Lesson(
|
|
||||||
// teacher = teacher.value,
|
|
||||||
// classNumber = classNumber.value.toInt(),
|
|
||||||
// time = time.value,
|
|
||||||
// dayOfWeekId = dayOfWeekId.value.toInt(),
|
|
||||||
// directionId = directionId.value.toInt()
|
|
||||||
// )
|
|
||||||
// lessonRepository.insertLesson(lesson)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fun delete(lesson: Lesson) = viewModelScope.launch {
|
|
||||||
// lessonRepository.deleteLesson(lesson)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fun getLessonByUid(uid: Int) = viewModelScope.launch {
|
|
||||||
// lessonRepository.getLessonByUid(uid)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fun update(lesson: Lesson) = viewModelScope.launch {
|
|
||||||
// lessonRepository.updateLesson(lesson)
|
|
||||||
// }
|
|
||||||
//}
|
|
@ -61,18 +61,18 @@
|
|||||||
"teacher": "Анна",
|
"teacher": "Анна",
|
||||||
"time": "9.00-10.00",
|
"time": "9.00-10.00",
|
||||||
"classNumber": 2,
|
"classNumber": 2,
|
||||||
"directionId": 1,
|
|
||||||
"dayOfWeekId": 1,
|
"dayOfWeekId": 1,
|
||||||
"countRecord": 7
|
"directionId": 1,
|
||||||
|
"countRecord": 6
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 3,
|
"id": 3,
|
||||||
"teacher": "Мария",
|
"teacher": "Мария",
|
||||||
"time": "17.00-18.00",
|
"time": "17.00-18.00",
|
||||||
"classNumber": 3,
|
"classNumber": 3,
|
||||||
"directionId": 3,
|
|
||||||
"dayOfWeekId": 2,
|
"dayOfWeekId": 2,
|
||||||
"countRecord": 3
|
"directionId": 3,
|
||||||
|
"countRecord": 2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 4,
|
"id": 4,
|
||||||
@ -90,7 +90,7 @@
|
|||||||
"classNumber": 6,
|
"classNumber": 6,
|
||||||
"dayOfWeekId": 5,
|
"dayOfWeekId": 5,
|
||||||
"directionId": 1,
|
"directionId": 1,
|
||||||
"countRecord": 7
|
"countRecord": 5
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"users": [
|
"users": [
|
||||||
@ -132,7 +132,7 @@
|
|||||||
"password": "user8",
|
"password": "user8",
|
||||||
"fio": "user8",
|
"fio": "user8",
|
||||||
"role": "User",
|
"role": "User",
|
||||||
"lessonId": null
|
"lessonId": 5
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user