Skip to content

Commit

Permalink
Merge pull request #110 from shaoyi1997/dashboard-feature
Browse files Browse the repository at this point in the history
Merge with mid-v1.3
  • Loading branch information
shaoyi1997 authored Oct 23, 2019
2 parents e9b901a + 0e9ccc8 commit f1862c4
Show file tree
Hide file tree
Showing 70 changed files with 1,369 additions and 461 deletions.
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
id 'jacoco'
id 'checkstyle'
id 'com.github.kt3k.coveralls' version '2.4.0'
id 'com.github.johnrengelman.shadow' version '4.0.4'
id 'com.github.johnrengelman.shadow' version '5.1.0'
id 'org.asciidoctor.convert' version '1.5.6'
id 'application'
}
Expand Down Expand Up @@ -72,9 +72,10 @@ dependencies {
}

shadowJar {
archiveName = 'addressbook.jar'

destinationDir = file("${buildDir}/jar/")
archiveBaseName = 'Mortago'
archiveVersion = "v1.2.1"
archiveClassifier = null
archiveAppendix = null
}

task coverage(type: JacocoReport) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import java.util.logging.Logger;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import seedu.address.commons.core.Config;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.core.Version;
Expand Down Expand Up @@ -36,7 +38,7 @@
*/
public class MainApp extends Application {

public static final Version VERSION = new Version(0, 6, 0, true);
public static final Version VERSION = new Version(1, 2, 1, true);

private static final Logger logger = LogsCenter.getLogger(MainApp.class);

Expand Down Expand Up @@ -168,6 +170,7 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {
@Override
public void start(Stage primaryStage) {
logger.info("Starting AddressBook " + MainApp.VERSION);
primaryStage.initStyle(StageStyle.TRANSPARENT);
ui.start(primaryStage);
}

Expand All @@ -179,5 +182,7 @@ public void stop() {
} catch (IOException e) {
logger.severe("Failed to save preferences " + StringUtil.getDetails(e));
}
Platform.exit();
System.exit(0);
}
}
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ public interface Logic {
* Selected body in the filtered body list.
* null if no body is selected.
*
* @see seedu.address.model.Model#selectedPersonProperty()
* @see seedu.address.model.Model#selectedBodyProperty()
*/
ReadOnlyProperty<Body> selectedBodyProperty();

/**
* Sets the selected person in the filtered person list.
* Sets the selected person in the filtered body list.
*
* @see seedu.address.model.Model#setSelectedPerson(Person)
* @see seedu.address.model.Model#setSelectedBody(Body)
*/
void setSelectedBody(Body body);
//@@ shaoyi1997-reused
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public CommandResult execute(Model model) throws CommandException {
model.addEntity(toAdd);

if (toAdd instanceof Body) {
SelectCommand selectCommand = new SelectCommand(toAdd.getIdNum().getIdNum());
selectCommand.execute(model);
Body body = (Body) toAdd;
NotifCommand notifCommand = new NotifCommand(new Notif(body), NOTIF_PERIOD, TimeUnit.SECONDS);
this.notifCommand = notifCommand;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
Expand All @@ -23,12 +24,13 @@ public class ClearCommand extends UndoableCommand {


@Override
public CommandResult execute(Model model) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
savedModel = new AddressBook(model.getAddressBook());
model.setAddressBook(new AddressBook());
UniqueIdentificationNumberMaps.clearAllEntries();

SelectCommand selectCommand = new SelectCommand(Integer.MAX_VALUE);
selectCommand.execute(model);
setUndoable();
model.addExecutedCommand(this);
return new CommandResult(MESSAGE_SUCCESS);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public CommandResult execute(Model model) throws CommandException {
targetIdNum.removeMapping();
setUndoable();
model.addExecutedCommand(this);
SelectCommand selectCommand = new SelectCommand(Integer.MAX_VALUE);
selectCommand.execute(model);
return new CommandResult(String.format(MESSAGE_DELETE_ENTITY_SUCCESS, entityToDelete));
} else {
throw new CommandException(Messages.MESSAGE_INVALID_ENTITY_DISPLAYED_INDEX);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/commands/NotifCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import seedu.address.model.entity.body.Body;
import seedu.address.model.notif.Notif;
import seedu.address.ui.NotifWindow;
import seedu.address.ui.NotificationButton;

//@@author arjavibahety

/**
* Notifies a user when there is an automatic change in BodyStatus.
*/
Expand Down Expand Up @@ -104,6 +104,7 @@ public void startSesChangeBodyStatusUi(Model model) throws CommandException {
logger.info("Error updating the body and fridge ");
}
}
NotificationButton.getInstanceOfNotifButton().setIconNumber(model.getNumberOfNotifs());
});

ses.schedule(changeUi, period, timeUnit);
Expand Down
31 changes: 15 additions & 16 deletions src/main/java/seedu/address/logic/commands/SelectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import static java.util.Objects.requireNonNull;

import java.util.List;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.entity.IdentificationNumber;
import seedu.address.model.entity.body.Body;

//@@ shaoyi1997-reused
Expand All @@ -26,32 +24,33 @@ public class SelectCommand extends Command {

public static final String MESSAGE_SELECT_BODY_SUCCESS = "Selected Body: %1$s";

private final Index targetIndex;
private final int targetId;

public SelectCommand(Index targetIndex) {
this.targetIndex = targetIndex;
public SelectCommand(int targetId) {
this.targetId = targetId;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

List<Body> filteredBodyList = model.getFilteredBodyList();

if (targetIndex.getZeroBased() >= filteredBodyList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_ENTITY_DISPLAYED_INDEX);
IdentificationNumber targetIdNum = IdentificationNumber.customGenerateId("B",
targetId);
if (!IdentificationNumber.isExistingIdentificationNumber(targetIdNum)) {
model.setSelectedBody(null);
if (targetId != Integer.MAX_VALUE) {
throw new CommandException(Messages.MESSAGE_INVALID_ENTITY_DISPLAYED_INDEX);
}
}

model.setSelectedBody(filteredBodyList.get(targetIndex.getZeroBased()));
return new CommandResult(String.format(MESSAGE_SELECT_BODY_SUCCESS, targetIndex.getOneBased()));

Body selectedBody = (Body) targetIdNum.getMapping();
model.setSelectedBody(selectedBody);
return new CommandResult(String.format(MESSAGE_SELECT_BODY_SUCCESS, targetId));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof SelectCommand // instanceof handles nulls
&& targetIndex.equals(((SelectCommand) other).targetIndex)); // state check
&& targetId == ((SelectCommand) other).targetId); // state check
}
}
//@@ shaoyi1997-reused
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/commands/UpdateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ public CommandResult execute(Model model) throws CommandException {
} else {
model.setEntity(entity, updateEntityDescriptor.apply(entity));
}
SelectCommand selectCommand = new SelectCommand(Integer.MAX_VALUE);
selectCommand.execute(model);
} catch (NullPointerException e) {
throw new CommandException(MESSAGE_ENTITY_NOT_FOUND);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ private static Body parseFieldsBody(ArgumentMultimap argMultimap) throws ParseEx
String details = ParserUtil.parseStringFields(argMultimap.getValue(PREFIX_BODY_DETAILS).orElse(""));
List<String> organsForDonation = ParserUtil.parseOrgansForDonation(
argMultimap.getValue(PREFIX_ORGANS_FOR_DONATION).orElse(""));
Religion religion = ParserUtil.parseReligion(argMultimap.getValue(PREFIX_RELIGION).orElse(""));
String relationship = ParserUtil.parseStringFields(argMultimap.getValue(PREFIX_RELATIONSHIP)
.orElse(""));
IdentificationNumber fridgeId = ParserUtil.parseIdentificationNumber(
argMultimap.getValue(PREFIX_FRIDGE_ID).orElse(""));
if (fridgeId != null) {
Expand All @@ -163,11 +166,8 @@ private static Body parseFieldsBody(ArgumentMultimap argMultimap) throws ParseEx
throw new ParseException(MESSAGE_INEXISTENT_FRIDGE);
}
}
Religion religion = ParserUtil.parseReligion(argMultimap.getValue(PREFIX_RELIGION).orElse(""));
String relationship = ParserUtil.parseStringFields(argMultimap.getValue(PREFIX_RELATIONSHIP)
.orElse(""));

return new Body(false, 1, dateOfAdmission, name, sex, nric, religion,
return new Body(dateOfAdmission, name, sex, nric, religion,
causeOfDeath, organsForDonation, status, fridgeId, dateOfBirth, dateOfDeath, nameNok, relationship,
phoneNok);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class CliSyntax {
public static final Prefix PREFIX_DATE_OF_ADMISSION = new Prefix("/doa");
public static final Prefix PREFIX_NRIC = new Prefix("/nric");
public static final Prefix PREFIX_RELIGION = new Prefix("/religion");
public static final Prefix PREFIX_NAME_NOK = new Prefix("/nameNOK");
public static final Prefix PREFIX_PHONE_NOK = new Prefix("/phoneNOK");
public static final Prefix PREFIX_NAME_NOK = new Prefix("/NOKname");
public static final Prefix PREFIX_PHONE_NOK = new Prefix("/NOKphone");
public static final Prefix PREFIX_CAUSE_OF_DEATH = new Prefix("/cod");
public static final Prefix PREFIX_BODY_DETAILS = new Prefix("/details");
public static final Prefix PREFIX_ORGANS_FOR_DONATION = new Prefix("/organsForDonation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class SelectCommandParser implements Parser<SelectCommand> {
public SelectCommand parse(String args) throws ParseException {
try {
Index index = ParserUtil.parseIndex(args);
return new SelectCommand(index);
return new SelectCommand(index.getOneBased());
} catch (ParseException pe) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, SelectCommand.MESSAGE_USAGE), pe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public UpdateBodyDescriptor(Body body) {
this.nric = body.getNric().orElse(null);
this.religion = body.getReligion().orElse(null);
this.causeOfDeath = body.getCauseOfDeath().orElse(null);
this.organsForDonation = body.getOrgansForDonation().orElse(null);
this.organsForDonation = body.getOrgansForDonation();
this.bodyStatus = body.getBodyStatus().orElse(null);
this.fridgeId = body.getFridgeId().orElse(null);
this.dateOfBirth = body.getDateOfBirth().orElse(null);
Expand Down Expand Up @@ -104,7 +104,7 @@ public Entity apply(Entity entity) {
body.setNric(this.getNric().orElse(body.getNric().orElse(null)));
body.setReligion(this.getReligion().orElse(body.getReligion().orElse(null)));
body.setCauseOfDeath(this.getCauseOfDeath().orElse(body.getCauseOfDeath().orElse(null)));
body.setOrgansForDonation(this.getOrgansForDonation().orElse(body.getOrgansForDonation().orElse(null)));
body.setOrgansForDonation(this.getOrgansForDonation().orElse(body.getOrgansForDonation()));
body.setBodyStatus(this.getBodyStatus().orElse(body.getBodyStatus().orElse(null)));
body.setFridgeId(this.getFridgeId().orElse(body.getFridgeId().orElse(null)));
body.setDateOfBirth(this.getDateOfBirth().orElse(body.getDateOfBirth().orElse(null)));
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public interface Model {
*/
void setNotif(Notif target, Notif editedNotif);

/**
* Returns the total number of notifications in the system.
*/
int getNumberOfNotifs();

/** Returns an unmodifiable view of the filtered person list */
ObservableList<Person> getFilteredPersonList();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ public void setNotif(Notif target, Notif editedNotif) {

addressBook.setNotif(target, editedNotif);
}

@Override
public int getNumberOfNotifs() {
return filteredNotifs.size();
}
//=========== Filtered Body List Accessors =============================================================
/**
* Returns an unmodifiable view of the list of {@code Worker} backed by the internal list of
Expand Down
1 change: 0 additions & 1 deletion src/main/java/seedu/address/model/UniqueNotifsList.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public void setNotifs(List<Notif> notifs) {
internalListNotifs.setAll(notifs);
}


/**
* Returns the backing Notif list as an unmodifiable {@code ObservableList}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class IdentificationNumber {
private int idNum;

private String typeOfEntity;
private boolean isTestId = false;

protected IdentificationNumber(Entity entity) {
requireNonNull(entity);
Expand Down Expand Up @@ -57,10 +56,9 @@ protected IdentificationNumber(Entity entity, int id) {
}
//@@author

private IdentificationNumber(String typeOfEntity, int idNum, boolean isTestId) {
private IdentificationNumber(String typeOfEntity, int idNum) {
this.typeOfEntity = typeOfEntity;
this.idNum = idNum;
this.isTestId = isTestId;
}

public static IdentificationNumber generateNewBodyId(Body body) {
Expand Down Expand Up @@ -88,11 +86,7 @@ public static IdentificationNumber generateNewFridgeId(Fridge fridge, int id) {
}

public static IdentificationNumber customGenerateId(String typeOfEntity, int idNum) {
return new IdentificationNumber(typeOfEntity, idNum, false);
}

public static IdentificationNumber customGenerateTestId(String typeOfEntity, int idNum) {
return new IdentificationNumber(typeOfEntity, idNum, true);
return new IdentificationNumber(typeOfEntity, idNum);
}

private static boolean isValidIdPrefix (String prefix) {
Expand Down Expand Up @@ -143,6 +137,13 @@ public static boolean isExistingIdentificationNumber(String fullIdString) {
}
}

/**
* Checks if given {@code IdentificationNumber id} already exists in Mortago.
*/
public static boolean isExistingIdentificationNumber(IdentificationNumber id) {
return isExistingIdentificationNumber(id.toString());
}

public String getTypeOfEntity() {
return typeOfEntity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ public static void clearAllEntries() {
uniqueWorkerMap.clear();
}

/**
* Returns the entity that belongs to the supplied Identification Number details.
* Guarantee: Identification Number is present and will not retrieve a null.
*/
public static Entity getMapping(String typeOfEntity, int id) {
if (typeOfEntity.equals("W")) {
return uniqueWorkerMap.get(id);
Expand Down
Loading

0 comments on commit f1862c4

Please sign in to comment.