Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
dinaraparanid committed Mar 5, 2021
1 parent b1c2922 commit 9a165c8
Show file tree
Hide file tree
Showing 17 changed files with 344 additions and 238 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "booklibrs"
version = "1.0.15"
version = "1.1.0"
authors = ["Paranid5 <[email protected]>"]
edition = "2018"
license = "MIT/Apache-2.0"
description = "Book libarary project including giveaway operations and gui interface."
homepage = "https://github.com/dinaraparanid/Library_rs"
documentation = "https://docs.rs/binartree/1.0.15/booklibrs/"
documentation = "https://docs.rs/binartree/1.1.0/booklibrs/"

[dependencies]
chrono = "0.4.19"
Expand Down
3 changes: 1 addition & 2 deletions src/actions/book/utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
extern crate fltk;

use fltk::dialog::alert;

use crate::{books::book_sys::BookSystem, Lang};
use fltk::dialog::alert;

/// Function that checks
/// if input of book was empty
Expand Down
32 changes: 9 additions & 23 deletions src/actions/genres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,17 @@ pub fn customize_book_genre(
500,
100,
300,
50 * genres.genres.len() as i32,
50 * genres.len() as i32,
match lang {
Lang::English => "Select Genres",
Lang::Russian => "Выбрать жанры",
},
);

let mut genre_choice =
CheckBrowser::new(0, 0, 300, 50 * genres.genres.len() as i32, "");
CheckBrowser::new(0, 0, 300, 50 * genres.len() as i32, "");

genres.genres.iter().for_each(|g| unsafe {
genres.iter().for_each(|g| unsafe {
genre_choice.add(
g.as_str(),
if let Some(gen) = &(**book_system.books.get_unchecked(index))
Expand All @@ -246,7 +246,7 @@ pub fn customize_book_genre(
wind.show();

while app.wait() {
(0..genres.genres.len()).for_each(|i| {
(0..genres.len()).for_each(|i| {
if genre_choice.checked(i as i32 + 1) {
unsafe {
if (**book_system.books.get_unchecked(index))
Expand All @@ -260,13 +260,7 @@ pub fn customize_book_genre(
.as_mut()
.unwrap()
.insert(
genres
.genres
.iter()
.skip(i)
.next()
.unwrap()
.clone(),
genres.iter().skip(i).next().unwrap().clone(),
);
} else {
(**book_system.books.get_unchecked(index))
Expand All @@ -279,13 +273,7 @@ pub fn customize_book_genre(
.as_mut()
.unwrap()
.insert(
genres
.genres
.iter()
.skip(i)
.next()
.unwrap()
.clone(),
genres.iter().skip(i).next().unwrap().clone(),
);
}
}
Expand All @@ -303,9 +291,7 @@ pub fn customize_book_genre(
.genres
.as_mut()
.unwrap()
.remove(
genres.genres.iter().skip(i).next().unwrap(),
);
.remove(genres.iter().skip(i).next().unwrap());

if (**book_system.books.get_unchecked(index))
.borrow()
Expand Down Expand Up @@ -350,7 +336,7 @@ pub fn find_by_genre_simple(
) -> Vec<(String, String, u16)> {
let mut find = vec![];

book_system.books.iter().for_each(|x| {
book_system.iter().for_each(|x| {
if (**x).borrow().genres.is_some()
&& (**x)
.borrow()
Expand Down Expand Up @@ -417,7 +403,7 @@ fn find_by_genre(book_system: &BookSystem, app: &App, lang: Lang) {
let mut book_table = Table::new(0, 0, 300, 400, "");
let mut find = vec![];

book_system.books.iter().for_each(|x| {
book_system.iter().for_each(|x| {
if (**x).borrow().genres.is_some()
&& (**x)
.borrow()
Expand Down
5 changes: 2 additions & 3 deletions src/actions/giveaway/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ pub fn change_return_date(
reader_base,
genres,
caretaker,
app,
lang,
);
}
Expand Down Expand Up @@ -230,15 +229,15 @@ pub fn get_book(
}

None => {
caretaker.pop();
caretaker.pop().unwrap();
return;
}
}
}
}
break;
} else if !inp.shown() {
caretaker.pop();
caretaker.pop().unwrap();
break;
}
}
Expand Down
134 changes: 124 additions & 10 deletions src/actions/giveaway/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use fltk::{
prelude::*,
};

use chrono::Local;
use chrono::{Datelike, Local};
use fltk_calendar::calendar::Calendar;
use std::{cell::RefCell, rc::Weak};

Expand Down Expand Up @@ -103,8 +103,7 @@ pub(crate) fn give_book_known_reader(
if msg {
win.hide();

let cal = Calendar::default();
let date = cal.get_date();
let date = Calendar::default().get_date();

return match date {
Some(date) => {
Expand Down Expand Up @@ -611,7 +610,6 @@ pub(crate) fn get_book_known_reader(
};

let bind = book_system
.books
.iter()
.position(|b| b.as_ptr() == book.as_ptr())
.unwrap();
Expand Down Expand Up @@ -775,7 +773,7 @@ fn get_book_known_reader_input(
}
},
);
caretaker.pop();
caretaker.pop().unwrap();
false
}

Expand Down Expand Up @@ -859,7 +857,7 @@ fn get_book_known_reader_input(
}
break;
} else if !inp2.shown() {
caretaker.pop();
caretaker.pop().unwrap();
return false;
}
}
Expand All @@ -872,6 +870,122 @@ fn get_book_known_reader_input(
#[inline]
pub fn change_return_date_simple(
book_op: &Option<Weak<RefCell<Book>>>,
book_system: &mut BookSystem,
reader_base: &ReaderBase,
genres: &Genres,
caretaker: &mut Caretaker,
lang: Lang,
) -> bool {
caretaker.add_memento(reader_base, book_system, genres);

return match book_op {
None => {
alert(
500,
500,
match lang {
Lang::English => "This reader isn't reading anything",
Lang::Russian => "Этот читатель ни читает книгу",
},
);

caretaker.pop().unwrap();
false
}

Some(book) => {
return match Calendar::default().get_date() {
None => {
alert(
500,
500,
match lang {
Lang::English => "Date wasn't selected",
Lang::Russian => "Дата не была выбрана",
},
);
false
}

Some(date) => {
let new_date = Date {
day: date.day() as u8,
month: date.month() as u8,
year: date.year() as u16,
};

let start = ((*(*book.upgrade().unwrap())
.borrow_mut()
.readers
.last_mut()
.unwrap())
.1)
.0;

if new_date >= start && new_date >= Date::from(Local::now()) {
((*(*book.upgrade().unwrap())
.borrow_mut()
.readers
.last_mut()
.unwrap())
.1)
.1 = new_date;

fltk::dialog::message(
500,
500,
match lang {
Lang::English => "Date is successfully changed",
Lang::Russian => "Дата успешно изменена",
},
);

book_system.save();
true
} else {
alert(
500,
500,
match lang {
Lang::English => {
concat!(
"Date can only be not earlier than deadline",
" and not earlier than today"
)
}

Lang::Russian => {
concat!(
"Дата обязана быть не позже дедлайна",
" и не позже сегоднешней даты"
)
}
},
);

caretaker.pop().unwrap();
false
}
}
}
}
};
}

/// **DEPRECATED**
///
/// Used before. Requires user input.
/// Consider using **change_return_date_simple() instead**
///
/// Function that changes
/// return date for already known book
#[allow(dead_code)]
#[deprecated(
note = "Used before. Requires user input. Consider using change_return_date_simple() instead"
)]
fn change_return_date_simple_input(
book_op: &Option<Weak<RefCell<Book>>>,
book_system: &mut BookSystem,
reader_base: &ReaderBase,
Expand Down Expand Up @@ -974,15 +1088,15 @@ pub fn change_return_date_simple(
match lang {
Lang::English => {
concat!(
"Date can only be not earlier than deadline",
" and not earlier than today"
"Date can only be not earlier than deadline",
" and not earlier than today"
)
}

Lang::Russian => {
concat!(
"Дата обязана быть не позже дедлайна",
" и не позже сегоднешней даты"
"Дата обязана быть не позже дедлайна",
" и не позже сегоднешней даты"
)
}
},
Expand Down
5 changes: 1 addition & 4 deletions src/actions/read/add_rem/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ pub fn add_reader(
if msg {
win.hide();

let cal = Calendar::default();
let date = cal.get_date();

match date {
match Calendar::default().get_date() {
Some(date) => {
match reader_base.add_reader(
unsafe { reader.get_unchecked(0).clone() },
Expand Down
6 changes: 1 addition & 5 deletions src/actions/read/change/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::{
};

use fltk::{app, app::App, dialog::alert, input::Input, prelude::*};

use fltk_calendar::calendar::Calendar;

/// Function that changes
Expand Down Expand Up @@ -384,10 +383,7 @@ pub(crate) fn change_age_simple(
if msg {
win.hide();

let cal = Calendar::default();
let date = cal.get_date();

return match date {
return match Calendar::default().get_date() {
Some(date) => match reader_base.change_age(ind, Date::from(date)) {
Ok(_) => {
fltk::dialog::message(
Expand Down
4 changes: 2 additions & 2 deletions src/actions/read/info/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ pub fn reader_info(
if let Some(ind) = check {
reader_info_simple(
ind,
&mut *(*reader_base).borrow_mut(),
&mut *(*book_system).borrow_mut(),
reader_base.clone(),
book_system.clone(),
genres,
caretaker,
app,
Expand Down
Loading

0 comments on commit 9a165c8

Please sign in to comment.