Commit 5ba9c3c96bdafec5dc2d47914fb786db46d7e2cf

Authored by kristinlaahneolsen
1 parent a2ede9b7

Nå fungerer loggføring i appen. Hver gang noen gjør endringer på en vurdering/ri…

…sko vil dato og hvilke felter som ble endret på sendt til server og hentet ut ved at bruker trykker på loggsymbolet. Det eneste som mangler er å kunne hente ut navn på den som er innlogget. FOreløpig er det bare et hardkodet navn til innloggingsbiten er ferdig
Risiko/app/src/main/java/activity/EditEvaluation.java
... ... @@ -14,6 +14,9 @@ import android.widget.Toast;
14 14  
15 15 import com.risiko.risiko.R;
16 16  
  17 +import java.text.DateFormat;
  18 +import java.text.SimpleDateFormat;
  19 +import java.util.Calendar;
17 20 import java.util.Date;
18 21 import java.util.Set;
19 22 import java.util.TreeSet;
... ... @@ -65,10 +68,6 @@ public class EditEvaluation extends AppCompatActivity {
65 68 etMeasures.setText(measures);
66 69  
67 70  
68   -
69   -
70   -
71   -
72 71 editEvaluation.setOnClickListener(view -> {
73 72 if (inputAccepted()) {
74 73 String stringConsequence = spinnerConsequence.getSelectedItem().toString();
... ... @@ -81,37 +80,32 @@ public class EditEvaluation extends AppCompatActivity {
81 80 String newOutcome = etOutcome.getText().toString();
82 81 String newMeasures = etMeasures.getText().toString();
83 82  
84   - Date date = new Date();
  83 + DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm");
  84 + Date dateChanged = Calendar.getInstance().getTime();
  85 + String logDate = df.format(dateChanged);
85 86  
86 87 Set<String> setInput = new TreeSet();
87 88  
88   - //TODO: SØRGE FOR AT DISSE IF-SETNINGENE GJØR DET DI SKAL, skal sendes med til databasen som EN string på hvilke felt som er endret
89   -
90 89 if(!newtitle.equals(title))
91 90 setInput.add("tittel");
92   - titleChanged = "tittel";
93 91 if(!newOutcome.equals(outcome))
94   - outcomeChanged = "Utfall endret";
95 92 setInput.add("utfall");
96 93 if(!newMeasures.equals(measures))
97   - measuresChanged = "Tiltak er endret";
98 94 setInput.add("tiltak");
99 95 if(consequenceValue!=consequence)
100 96 setInput.add("konsekvens");
101   - consequenceChanged = "Konsekvens er endret";
102 97 if(probabilityValue!=probability )
103 98 setInput.add("sannsynlighet");
104   - probabilityChanged = "Sannsynlighet er endret";
105 99  
106 100 StringBuilder sb= new StringBuilder();
107 101  
108 102 for(String tempString:setInput){
109 103 sb.append(tempString).append(", ");
110 104 }
111   - String finalS = sb.toString();
112   - System.out.println("FØLGENDE FELT BLE OPPDATERT: " + finalS);
113 105  
114   - System.out.println(allFieldsChanged + "\n" + titleChanged + "\n" + outcomeChanged + "\n"+ measuresChanged + "\n" + consequenceChanged + "\n" + probabilityChanged);
  106 + String fieldschanged = sb.toString();
  107 + System.out.println("FØLGENDE FELT BLE OPPDATERT: " + fieldschanged);
  108 + logchanges(fieldschanged, logDate, id);
115 109  
116 110 Api.get().editEvaluation(id, newtitle, newOutcome, newMeasures, consequenceValue, probabilityValue, assosiatedActivity).enqueue(new Callback<Evaluation>() {
117 111 @Override
... ... @@ -133,6 +127,24 @@ public class EditEvaluation extends AppCompatActivity {
133 127 });
134 128 }
135 129  
  130 + //TODO: HENT UT DET FAKTISKE BRUKERNAVNET
  131 +
  132 + private void logchanges(String fieldsChanged, String date, String assosiatedEval) {
  133 + Api.get().newLogEntry("Anne Liane", date, fieldsChanged, assosiatedEval).enqueue(new Callback<String>() {
  134 + @Override
  135 + public void onResponse(Call<String> call, Response<String> response) {
  136 + System.out.println(response);
  137 + }
  138 +
  139 + @Override
  140 + public void onFailure(Call<String> call, Throwable t) {
  141 + t.printStackTrace();
  142 +
  143 + }
  144 + });
  145 +
  146 + }
  147 +
136 148  
137 149 private void goBackToActivities() {
138 150 Intent intent = new Intent(this, Activities.class);
... ...
Risiko/app/src/main/java/adapters/ListAdapterEvaluationLog.java
... ... @@ -33,10 +33,10 @@ public class ListAdapterEvaluationLog extends ArrayAdapter&lt;EvaluationLog&gt; {
33 33 logDate.setText(log.getDate());
34 34  
35 35 TextView logName = convertView.findViewById(R.id.tv_log_name);
36   - logName.setText(log.getName());
  36 + logName.setText("Endret av: " + log.getName());
37 37  
38 38 TextView logFieldsChanged = convertView.findViewById(R.id.tv_changed_fields);
39   - logFieldsChanged.setText(log.getChangedfields());
  39 + logFieldsChanged.setText("Følgende felt ble endret: " + log.getChangedfields());
40 40  
41 41 return convertView;
42 42 }
... ...
Risiko/app/src/main/java/api/Endpoints.java
... ... @@ -77,8 +77,11 @@ public interface Endpoints {
77 77 Call<Incident> editIncident(@Path("id") String id, @Field("date") String date, @Field("location") String location,
78 78 @Field("title") String title, @Field("description") String description, @Field("associatedEval") String associatedEval);
79 79  
80   -
81 80 @GET("evaluation/{assosiatedeval}/evaluationlog")
82 81 Call<List<EvaluationLog>> getEvaluationLog(@Path("assosiatedeval") String assosiatedeval);
83 82  
  83 + @FormUrlEncoded
  84 + @POST("evaluationlog")
  85 + Call<String> newLogEntry(@Field("name") String name, @Field("date") String date, @Field("changedfields") String changedfields, @Field("associatedeval") String associatedeval);
  86 +
84 87 }
... ...
Risiko/app/src/main/res/layout/evaluationloglist.xml
... ... @@ -21,7 +21,7 @@
21 21 android:layout_width="wrap_content"
22 22 android:layout_height="wrap_content"
23 23 android:layout_marginRight="10dp"
24   - android:textSize="20dp"
  24 + android:textSize="17dp"
25 25 android:text="Dato sist endret "/>
26 26  
27 27 <TextView
... ... @@ -30,7 +30,7 @@
30 30 android:layout_width="wrap_content"
31 31 android:layout_height="wrap_content"
32 32 android:layout_marginBottom="10dp"
33   - android:textSize="20dp"
  33 + android:textSize="17dp"
34 34 android:text="Av: Ola Nordmann"/>
35 35  
36 36  
... ... @@ -42,7 +42,7 @@
42 42 android:layout_width="wrap_content"
43 43 android:layout_height="wrap_content"
44 44 android:layout_marginBottom="10dp"
45   - android:textSize="20dp"
  45 + android:textSize="17dp"
46 46 android:text="Felt som er endret"/>
47 47  
48 48 </LinearLayout>
... ...
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$/api/routes/routes.js" afterPath="$PROJECT_DIR$/api/routes/routes.js" />
6   - </list>
  4 + <list default="true" id="0e20d303-9de8-4113-bfd9-019e72b304dc" name="Default" comment="" />
7 5 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
8 6 <option name="TRACKING_ENABLED" value="true" />
9 7 <option name="SHOW_DIALOG" value="false" />
... ... @@ -50,8 +48,8 @@
50 48 <file leaf-file-name="routes.js" pinned="false" current-in-tab="true">
51 49 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
52 50 <provider selected="true" editor-type-id="text-editor">
53   - <state relative-caret-position="464">
54   - <caret line="406" column="42" lean-forward="true" selection-start-line="406" selection-start-column="42" selection-end-line="406" selection-end-column="42" />
  51 + <state relative-caret-position="395">
  52 + <caret line="412" column="0" lean-forward="true" selection-start-line="412" selection-start-column="0" selection-end-line="412" selection-end-column="0" />
55 53 <folding />
56 54 </state>
57 55 </provider>
... ... @@ -241,24 +239,24 @@
241 239 <workItem from="1541681303243" duration="9060000" />
242 240 <workItem from="1542189792461" duration="7537000" />
243 241 <workItem from="1542881688157" duration="372000" />
244   - <workItem from="1543226716067" duration="6979000" />
  242 + <workItem from="1543226716067" duration="7767000" />
245 243 </task>
246 244 <servers />
247 245 </component>
248 246 <component name="TimeTrackingManager">
249   - <option name="totallyTimeSpent" value="36670000" />
  247 + <option name="totallyTimeSpent" value="37458000" />
250 248 </component>
251 249 <component name="ToolWindowManager">
252   - <frame x="0" y="0" width="1045" height="900" extended-state="6" />
  250 + <frame x="0" y="0" width="1030" height="900" extended-state="6" />
253 251 <editor active="true" />
254 252 <layout>
255   - <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.13476562" sideWeight="0.69244605" order="0" side_tool="false" content_ui="combo" />
  253 + <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.13676907" sideWeight="0.69244605" order="0" side_tool="false" content_ui="combo" />
256 254 <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" />
257 255 <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" />
258 256 <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" />
259 257 <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32769045" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
260 258 <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" />
261   - <window_info id="npm" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.13476562" sideWeight="0.30755395" order="2" side_tool="true" content_ui="tabs" />
  259 + <window_info id="npm" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.13676907" sideWeight="0.30755395" order="2" side_tool="true" content_ui="tabs" />
262 260 <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" />
263 261 <window_info id="Terminal" 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="9" side_tool="false" content_ui="tabs" />
264 262 <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.39903265" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
... ... @@ -365,8 +363,8 @@
365 363 </entry>
366 364 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
367 365 <provider selected="true" editor-type-id="text-editor">
368   - <state relative-caret-position="464">
369   - <caret line="406" column="42" lean-forward="true" selection-start-line="406" selection-start-column="42" selection-end-line="406" selection-end-column="42" />
  366 + <state relative-caret-position="395">
  367 + <caret line="412" column="0" lean-forward="true" selection-start-line="412" selection-start-column="0" selection-end-line="412" selection-end-column="0" />
370 368 <folding />
371 369 </state>
372 370 </provider>
... ...