Commit 93b94e8cab97f7fc7674025e3b5cf350f6853f65

Authored by kristinlaahneolsen
1 parent 3dca8281

Nå fungerer det å endre assosiert risiko tilknyttet en hendelse vha dropdownlist…

…a. Har også måtte endret på endpointet getEvaluation, for på den måten får vi ut tittelen til den assosierte risikoen i hendelses-opplistinga
Risiko/app/src/main/java/activity/EditIncident.java
1 1 package activity;
2 2  
3 3 import android.content.Intent;
4   -import android.support.v7.app.AppCompatActivity;
5 4 import android.os.Bundle;
  5 +import android.support.v7.app.AppCompatActivity;
6 6 import android.util.Log;
7 7 import android.widget.ArrayAdapter;
8 8 import android.widget.Button;
... ... @@ -14,10 +14,9 @@ import com.risiko.risiko.R;
14 14  
15 15 import java.util.HashMap;
16 16 import java.util.List;
17   -import java.util.UUID;
18 17  
19 18 import api.Api;
20   -import dataclasses.*;
  19 +import dataclasses.Evaluation;
21 20 import dataclasses.Incident;
22 21 import retrofit2.Call;
23 22 import retrofit2.Callback;
... ... @@ -44,9 +43,6 @@ public class EditIncident extends AppCompatActivity {
44 43 String description = b.getString("description");
45 44 String assosiatedEval = b.getString("assosiatedEval");
46 45  
47   -
48   - System.out.println("SE HIT" + id + "\n" + title + "\n" + date + "\n" + location + "\n" + description );
49   -
50 46 etDate = findViewById(R.id.et_edit_incident_date);
51 47 etLocation = findViewById(R.id.et_edit_incident_location);
52 48 etTitle = findViewById(R.id.et_edit_incident_title);
... ... @@ -59,11 +55,7 @@ public class EditIncident extends AppCompatActivity {
59 55 etTitle.setText(title);
60 56 etDescription.setText(description);
61 57  
62   -
63   -
64   -
65 58 spinnerAssociatedRisk = findViewById(R.id.spinner_associated_risk);
66   -// dbs.getAllEvaluation(evaluations);
67 59  
68 60 Api.get().getAllEvaluations()
69 61 .enqueue(new Callback<List<Evaluation>>() {
... ... @@ -77,54 +69,51 @@ public class EditIncident extends AppCompatActivity {
77 69 ArrayAdapter<Object> adapter = new ArrayAdapter<>(EditIncident.this, android.R.layout.simple_spinner_item, evalMap.keySet().toArray());
78 70 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
79 71 spinnerAssociatedRisk.setAdapter(adapter);
  72 + String associatedRiskTitle = spinnerAssociatedRisk.getSelectedItem().toString();
  73 + String associatedRisk = evalMap.get(associatedRiskTitle);
80 74  
81   - }
82   - }
83   - }
  75 + editIncident.setOnClickListener(view -> {
  76 + if (inputAccepted()) {
84 77  
85   - @Override
86   - public void onFailure(Call<List<dataclasses.Evaluation>> call, Throwable t) {
87   - //Something went completely south (maybe you lost internet connection)
88   - Toast.makeText(EditIncident.this, "Something went wrong",
89   - Toast.LENGTH_LONG).show();
90   - Log.d("Error", t.getMessage());
91   - }
92   - });
93   -
94   - editIncident.setOnClickListener(view -> {
95   - if (inputAccepted()) {
96   -
97   - String newtitle = etTitle.getText().toString();
98   - String newdate = etDate.getText().toString();
99   - String newlocation = etLocation.getText().toString();
100   - String newdescription = etDescription.getText().toString();
101   -
102   - //TODO: MANGLER ASSOSIATEDEVAL-SPINNERTING
103   - Api.get().editIncident(id, newdate, newlocation, newtitle, newdescription, assosiatedEval).enqueue(new Callback<dataclasses.Incident>() {
104   - @Override
105   - public void onResponse(Call<Incident> call, Response<Incident> response) {
106   - System.out.println(response);
107   - System.out.println("ALT I ORDEN");
  78 + String newtitle = etTitle.getText().toString();
  79 + String newdate = etDate.getText().toString();
  80 + String newlocation = etLocation.getText().toString();
  81 + String newdescription = etDescription.getText().toString();
108 82  
  83 + Api.get().editIncident(id, newdate, newlocation, newtitle, newdescription, associatedRisk).enqueue(new Callback<dataclasses.Incident>() {
  84 + @Override
  85 + public void onResponse(Call<Incident> call, Response<Incident> response) {
  86 + System.out.println(response);
109 87  
110   - }
  88 + }
111 89  
112 90  
113   - @Override
114   - public void onFailure(Call<Incident> call, Throwable t) {
115   - t.printStackTrace();
116   - System.out.println("NOE FEILET");
117   - }
  91 + @Override
  92 + public void onFailure(Call<Incident> call, Throwable t) {
  93 + t.printStackTrace();
  94 + }
118 95  
  96 + });
  97 + }
119 98  
120   - });
121   - }
  99 + finish();
  100 + goBackToIncidents();
  101 +
  102 + });
122 103  
123   - finish();
124   - goBackToIncidents();
125 104  
126   - });
  105 + }
  106 + }
  107 + }
127 108  
  109 + @Override
  110 + public void onFailure(Call<List<dataclasses.Evaluation>> call, Throwable t) {
  111 + //Something went completely south (maybe you lost internet connection)
  112 + Toast.makeText(EditIncident.this, "Something went wrong",
  113 + Toast.LENGTH_LONG).show();
  114 + Log.d("Error", t.getMessage());
  115 + }
  116 + });
128 117  
129 118  
130 119 }
... ... @@ -143,13 +132,13 @@ public class EditIncident extends AppCompatActivity {
143 132 return true;
144 133 }
145 134  
146   - private HashMap<String, String> convertToDictionaryWithIdAndTitle(List<Evaluation> evaluations) {
147   - HashMap<String, String> evalMap = new HashMap<>();
148   - for (Evaluation e : evaluations) {
149   - evalMap.put(e.getTitle(), e.getId());
150   - }
151   - return evalMap;
152   - }
  135 + private HashMap<String, String> convertToDictionaryWithIdAndTitle(List<Evaluation> evaluations) {
  136 + HashMap<String, String> evalMap = new HashMap<>();
  137 + for (Evaluation e : evaluations) {
  138 + evalMap.put(e.getTitle(), e.getId());
  139 + }
  140 + return evalMap;
  141 + }
153 142  
154 143 }
155 144  
... ...
Risiko/app/src/main/java/activity/Incident.java
... ... @@ -96,12 +96,32 @@ public class Incident extends AppCompatActivity {
96 96  
97 97 deleteEvent.setOnClickListener(view -> deleteEventDialog());
98 98 editEvent.setOnClickListener(view -> editIncident(chosenItem.getId(), chosenItem.getTitle(), chosenItem.getDate(), chosenItem.getDescription(), chosenItem.getLocation(), chosenItem.getAssociatedeval()));
  99 +
  100 +
  101 + System.out.println("EVALID" + chosenItem.getAssociatedeval());
  102 + Api.get().getEvaluation(chosenItem.getAssociatedeval()).enqueue(new Callback<Evaluation>() {
  103 + @Override
  104 + public void onResponse(Call<Evaluation> call, Response<Evaluation> response) {
  105 + Evaluation evaluation = response.body();
  106 + String evaluationTitle = evaluation.getTitle();
  107 + tvAssociatedRisk.setText(evaluationTitle);
  108 + }
  109 +
  110 + @Override
  111 + public void onFailure(Call<Evaluation> call, Throwable t) {
  112 + System.out.println("FEILAAA");
  113 +
  114 + }
  115 + });
  116 +
  117 +
99 118 tvTitle.setText(chosenItem.getTitle());
100 119 tvDate.setText(chosenItem.getDate());
101 120 tvLocation.setText(chosenItem.getLocation());
102 121 tvDescription.setText(chosenItem.getDescription());
  122 +
103 123 Evaluation associatedEvaluation = dbs.getEvaluationById(chosenItem.getAssociatedeval());
104   - tvAssociatedRisk.setText(associatedEvaluation.getTitle());
  124 +
105 125  
106 126 alertDialogBuilder.setCancelable(false)
107 127 .setNegativeButton(getString(R.string.cancel),
... ...
Risiko/app/src/main/java/api/Endpoints.java
... ... @@ -38,7 +38,7 @@ public interface Endpoints {
38 38 Call<List<Evaluation>> getAllEvaluations();
39 39  
40 40 @GET("evaluation/{id}")
41   - Call<List<Evaluation>> getEvaluation(@Path("id") String id);
  41 + Call<Evaluation> getEvaluation(@Path("id") String id);
42 42  
43 43 @GET("activity")
44 44 Call<List<Activity>> getAllActivities();
... ...
restApi/.idea/workspace.xml
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <project version="4">
3 3 <component name="ChangeListManager">
4   - <list default="true" id="0e20d303-9de8-4113-bfd9-019e72b304dc" name="Default" comment="">
5   - <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/EditIncident.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/EditIncident.java" />
6   - <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" />
7   - <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
8   - </list>
  4 + <list default="true" id="0e20d303-9de8-4113-bfd9-019e72b304dc" name="Default" comment="" />
9 5 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
10 6 <option name="TRACKING_ENABLED" value="true" />
11 7 <option name="SHOW_DIALOG" value="false" />
... ... @@ -103,7 +99,7 @@
103 99 <path value="$PROJECT_DIR$/package.json" />
104 100 </packageJsonPaths>
105 101 </component>
106   - <component name="ProjectFrameBounds" extendedState="1">
  102 + <component name="ProjectFrameBounds" extendedState="6">
107 103 <option name="y" value="23" />
108 104 <option name="width" value="1440" />
109 105 <option name="height" value="873" />
... ... @@ -222,22 +218,22 @@
222 218 <workItem from="1541155443683" duration="1473000" />
223 219 <workItem from="1541596156631" duration="9351000" />
224 220 <workItem from="1541681303243" duration="9060000" />
225   - <workItem from="1542189792461" duration="6867000" />
  221 + <workItem from="1542189792461" duration="7537000" />
226 222 </task>
227 223 <servers />
228 224 </component>
229 225 <component name="TimeTrackingManager">
230   - <option name="totallyTimeSpent" value="28649000" />
  226 + <option name="totallyTimeSpent" value="29319000" />
231 227 </component>
232 228 <component name="ToolWindowManager">
233   - <frame x="0" y="23" width="1440" height="873" extended-state="1" />
  229 + <frame x="0" y="23" width="1440" height="873" extended-state="6" />
234 230 <layout>
235 231 <window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.20014094" sideWeight="0.71128106" order="0" side_tool="false" content_ui="combo" />
236 232 <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
237 233 <window_info id="Docker" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
238 234 <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="10" side_tool="true" content_ui="tabs" />
239 235 <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
240   - <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.3277635" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
  236 + <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3277635" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
241 237 <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
242 238 <window_info id="npm" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.20014094" sideWeight="0.28871894" order="2" side_tool="true" content_ui="tabs" />
243 239 <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
... ...