Commit d8c4185042abe7b798cc12ac444cc8b59b17504f

Authored by kristinlaahneolsen
1 parent 26c699a7

Har laget klar dataklasse + adapter + egen aktivitet for å hente ut logg. Tror d…

…ette blir den mest oversiktlige måten å gjøre det på. Todo: må lage tabeller til dette i databasen og metode for å hente ut logg i Api. Må også sørge for at når innloggingen er på plass, at navn til bruker  blir sendt med i loggen ved endring
Risiko/app/src/main/AndroidManifest.xml
... ... @@ -27,7 +27,8 @@
27 27 <activity android:name="activity.SequenceOfActivities" />
28 28 <activity android:name="activity.EditIncident" />
29 29 <activity android:name="activity.Log" />
30   - <activity android:name="activity.EditEvaluation"></activity>
  30 + <activity android:name="activity.EditEvaluation" />
  31 + <activity android:name="activity.EvaluationLog"></activity>
31 32 </application>
32 33  
33 34 </manifest>
34 35 \ No newline at end of file
... ...
Risiko/app/src/main/java/activity/EditEvaluation.java
1 1 package activity;
2 2  
3 3 import android.content.Intent;
  4 +import android.icu.util.Measure;
4 5 import android.support.v7.app.AppCompatActivity;
5 6 import android.os.Bundle;
6 7 import android.support.v7.widget.Toolbar;
... ... @@ -13,6 +14,10 @@ import android.widget.Toast;
13 14  
14 15 import com.risiko.risiko.R;
15 16  
  17 +import java.util.Date;
  18 +import java.util.Set;
  19 +import java.util.TreeSet;
  20 +
16 21 import api.Api;
17 22 import dataclasses.*;
18 23 import retrofit2.Call;
... ... @@ -25,7 +30,7 @@ public class EditEvaluation extends AppCompatActivity {
25 30 private EditText etMeasures;
26 31 private Spinner spinnerConsequence, spinnerProbability;
27 32 Button editEvaluation;
28   -
  33 + String allFieldsChanged, titleChanged, measuresChanged, outcomeChanged, consequenceChanged, probabilityChanged;
29 34  
30 35  
31 36 @Override
... ... @@ -60,19 +65,54 @@ public class EditEvaluation extends AppCompatActivity {
60 65 etMeasures.setText(measures);
61 66  
62 67  
63   - String stringConsequence = spinnerConsequence.getSelectedItem().toString();
64   - String stringProbability = spinnerProbability.getSelectedItem().toString();
65 68  
66   - int consequenceValue = getConsequenceValue(stringConsequence);
67   - int probabilityValue = getProbabilityValue(stringProbability);
  69 +
  70 +
68 71  
69 72 editEvaluation.setOnClickListener(view -> {
70 73 if (inputAccepted()) {
  74 + String stringConsequence = spinnerConsequence.getSelectedItem().toString();
  75 + String stringProbability = spinnerProbability.getSelectedItem().toString();
  76 +
  77 + int consequenceValue = getConsequenceValue(stringConsequence);
  78 + int probabilityValue = getProbabilityValue(stringProbability);
71 79  
72 80 String newtitle = etTitle.getText().toString();
73 81 String newOutcome = etOutcome.getText().toString();
74 82 String newMeasures = etMeasures.getText().toString();
75 83  
  84 + Date date = new Date();
  85 +
  86 + Set<String> setInput = new TreeSet();
  87 +
  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 + if(!newtitle.equals(title))
  91 + setInput.add("tittel");
  92 + titleChanged = "tittel";
  93 + if(!newOutcome.equals(outcome))
  94 + outcomeChanged = "Utfall endret";
  95 + setInput.add("utfall");
  96 + if(!newMeasures.equals(measures))
  97 + measuresChanged = "Tiltak er endret";
  98 + setInput.add("tiltak");
  99 + if(consequenceValue!=consequence)
  100 + setInput.add("konsekvens");
  101 + consequenceChanged = "Konsekvens er endret";
  102 + if(probabilityValue!=probability )
  103 + setInput.add("sannsynlighet");
  104 + probabilityChanged = "Sannsynlighet er endret";
  105 +
  106 + StringBuilder sb= new StringBuilder();
  107 +
  108 + for(String tempString:setInput){
  109 + sb.append(tempString).append(", ");
  110 + }
  111 + String finalS = sb.toString();
  112 + System.out.println("FØLGENDE FELT BLE OPPDATERT: " + finalS);
  113 +
  114 + System.out.println(allFieldsChanged + "\n" + titleChanged + "\n" + outcomeChanged + "\n"+ measuresChanged + "\n" + consequenceChanged + "\n" + probabilityChanged);
  115 +
76 116 Api.get().editEvaluation(id, newtitle, newOutcome, newMeasures, consequenceValue, probabilityValue, assosiatedActivity).enqueue(new Callback<Evaluation>() {
77 117 @Override
78 118 public void onResponse(Call<Evaluation> call, Response<Evaluation> response) {
... ...
Risiko/app/src/main/java/activity/EvaluationLog.java 0 → 100644
  1 +package activity;
  2 +
  3 +import android.content.Intent;
  4 +import android.support.v7.app.AppCompatActivity;
  5 +import android.os.Bundle;
  6 +import android.support.v7.widget.Toolbar;
  7 +import android.view.Menu;
  8 +import android.view.MenuItem;
  9 +import android.widget.ListView;
  10 +import android.widget.Toast;
  11 +
  12 +import com.risiko.risiko.R;
  13 +
  14 +import java.util.ArrayList;
  15 +import java.util.Date;
  16 +import java.util.List;
  17 +
  18 +import adapters.ListAdapterActivities;
  19 +import adapters.ListAdapterEvaluationLog;
  20 +import dataclasses.Activity;
  21 +import dataclasses.Evaluation;
  22 +
  23 +public class EvaluationLog extends AppCompatActivity {
  24 + ListView lv;
  25 +
  26 + @Override
  27 + protected void onCreate(Bundle savedInstanceState) {
  28 + super.onCreate(savedInstanceState);
  29 + setContentView(R.layout.activity_evaluation_log);
  30 + Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
  31 + setSupportActionBar(myToolbar);
  32 +
  33 +
  34 + List<dataclasses.EvaluationLog> log = new ArrayList<>();
  35 + log.add(new dataclasses.EvaluationLog("Ola Nordmann", "2015-02-02", "Alle"));
  36 + log.add(new dataclasses.EvaluationLog("Kari Nordmann", "2015-01-02", "Konsekvens"));
  37 + insertLog(log);
  38 + }
  39 +
  40 + private void insertLog(List<dataclasses.EvaluationLog> log) {
  41 + lv = findViewById(R.id.lv_log);
  42 + lv.setAdapter(new ListAdapterEvaluationLog(this, log));
  43 + }
  44 +
  45 +
  46 + @Override
  47 + public boolean onCreateOptionsMenu (Menu menu) {
  48 + getMenuInflater().inflate(R.menu.main, menu);
  49 + return true;
  50 + }
  51 +
  52 + @Override
  53 + public boolean onOptionsItemSelected(MenuItem item) {
  54 + switch (item.getItemId()) {
  55 + case R.id.action_logout:
  56 + //TODO: LEGG TIL LOGG-UT-FUNKSJON
  57 + Toast.makeText(EvaluationLog.this, "Logger ut",
  58 + Toast.LENGTH_LONG).show();
  59 + return true;
  60 +
  61 + case R.id.action_home:
  62 + Intent intent = new Intent(this, MainMenu.class);
  63 + startActivity(intent);
  64 + return true;
  65 +
  66 + default:
  67 + return super.onOptionsItemSelected(item);
  68 +
  69 + }
  70 + }
  71 +}
... ...
Risiko/app/src/main/java/activity/Evaluations.java
... ... @@ -130,6 +130,8 @@ public class Evaluations extends AppCompatActivity {
130 130 TextView addedBy = promptView.findViewById(R.id.tv_added_by);
131 131  
132 132 Button updateEvaluation = promptView.findViewById(R.id.pop_edit_evaluation);
  133 + Button evaluationLog = promptView.findViewById(R.id.pop_log);
  134 + evaluationLog.setOnClickListener(view -> startActivity(new Intent(this, EvaluationLog.class)));
133 135 updateEvaluation.setOnClickListener(view -> editEvaluation(evaluation.getTitle(), evaluation.getOutcome(),
134 136 evaluation.getMeasures(), evaluation.getConsequence(), evaluation.getProbability(), evaluation.getId(), evaluation.getAssociatedactivity()));
135 137  
... ...
Risiko/app/src/main/java/adapters/ListAdapterEvaluationLog.java 0 → 100644
  1 +package adapters;
  2 +
  3 +
  4 +import android.content.Context;
  5 +import android.support.annotation.NonNull;
  6 +import android.view.LayoutInflater;
  7 +import android.view.View;
  8 +import android.view.ViewGroup;
  9 +import android.widget.ArrayAdapter;
  10 +import android.widget.TextView;
  11 +
  12 +import com.risiko.risiko.R;
  13 +
  14 +import java.util.List;
  15 +
  16 +import dataclasses.Activity;
  17 +import dataclasses.EvaluationLog;
  18 +
  19 +public class ListAdapterEvaluationLog extends ArrayAdapter<EvaluationLog> {
  20 +
  21 + public ListAdapterEvaluationLog(@NonNull Context context, List<EvaluationLog> log) {
  22 + super(context, R.layout.activity_evaluation_log, log);
  23 + }
  24 +
  25 + @NonNull
  26 + @Override
  27 + public View getView(int position, View convertView, @NonNull ViewGroup parent) {
  28 + EvaluationLog log = getItem(position);
  29 + if (convertView == null) {
  30 + convertView = LayoutInflater.from(getContext()).inflate(R.layout.evaluationloglist, parent, false);
  31 + }
  32 +
  33 + TextView logDate = convertView.findViewById(R.id.tv_log_date);
  34 + logDate.setText(log.getDate());
  35 +
  36 + TextView logName = convertView.findViewById(R.id.tv_log_name);
  37 + logName.setText(log.getName());
  38 +
  39 + TextView logFieldsChanged = convertView.findViewById(R.id.tv_changed_fields);
  40 + logFieldsChanged.setText(log.getChangedFields());
  41 +
  42 + return convertView;
  43 + }
  44 +
  45 +}
  46 +
  47 +
  48 +
... ...
Risiko/app/src/main/java/dataclasses/EvaluationLog.java 0 → 100644
  1 +package dataclasses;
  2 +
  3 +/**
  4 + * Created by kristinlaahneolsen on 26.11.2018.
  5 + */
  6 +
  7 +public class EvaluationLog {
  8 + private String name;
  9 + private String date;
  10 + private String changedFields;
  11 +
  12 +
  13 + public EvaluationLog(String name, String date, String changedFields) {
  14 + this.name = name;
  15 + this.date = date;
  16 + this.changedFields = changedFields;
  17 + }
  18 +
  19 + public String getName() {
  20 + return name;
  21 + }
  22 +
  23 + public void setName(String name) {
  24 + this.name = name;
  25 + }
  26 +
  27 +
  28 + public String getDate() {
  29 + return date;
  30 + }
  31 +
  32 + public void setDate(String date) {
  33 + this.date = date;
  34 + }
  35 +
  36 + public String getChangedFields() {
  37 + return changedFields;
  38 + }
  39 +
  40 + public void setChangedFields(String changedFields) {
  41 + this.changedFields = changedFields;
  42 + }
  43 +}
... ...
Risiko/app/src/main/res/drawable/ic_eye_white.xml 0 → 100644
  1 +<vector xmlns:android="http://schemas.android.com/apk/res/android"
  2 + android:width="24dp"
  3 + android:height="24dp"
  4 + android:viewportWidth="24.0"
  5 + android:viewportHeight="24.0">
  6 + <path
  7 + android:fillColor="#ffffff"
  8 + android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"/>
  9 +</vector>
... ...
Risiko/app/src/main/res/layout/activity_evaluation_log.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +
  3 +<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4 + xmlns:app="http://schemas.android.com/apk/res-auto"
  5 + xmlns:tools="http://schemas.android.com/tools"
  6 + android:layout_width="match_parent"
  7 + android:layout_height="match_parent">
  8 +
  9 + <include layout="@layout/toolbar"/>
  10 +
  11 + <TextView
  12 + android:id="@+id/headline"
  13 + android:layout_width="wrap_content"
  14 + android:layout_height="wrap_content"
  15 + android:text="Hendelseslogg"
  16 + android:textStyle="bold"
  17 + android:textSize="25dp"
  18 + android:textColor="@color/colorPrimaryDark"
  19 + app:layout_constraintLeft_toLeftOf="parent"
  20 + app:layout_constraintRight_toRightOf="parent"
  21 + app:layout_constraintTop_toTopOf="parent"
  22 + android:layout_marginTop="70dp"
  23 + android:layout_marginBottom="100dp" />
  24 +
  25 +
  26 + <android.support.constraint.ConstraintLayout
  27 + app:layout_constraintTop_toBottomOf="@+id/headline"
  28 + android:layout_width="match_parent"
  29 + android:layout_height="match_parent"
  30 + android:layout_marginVertical="70dp"
  31 + android:layout_marginBottom="20dp">
  32 +
  33 +
  34 + <android.support.v4.widget.SwipeRefreshLayout
  35 + xmlns:android="http://schemas.android.com/apk/res/android"
  36 + android:id="@+id/swiperefresh"
  37 + android:layout_marginTop="50dp"
  38 + android:layout_width="match_parent"
  39 + android:layout_height="match_parent">
  40 +
  41 +
  42 + <LinearLayout
  43 + android:layout_marginTop="200dp"
  44 + android:background="@color/colorWhite"
  45 + android:layout_width="match_parent"
  46 + android:layout_height="match_parent"
  47 + android:orientation="vertical">
  48 +
  49 + <ListView
  50 + android:id="@+id/lv_log"
  51 + android:layout_margin="10dp"
  52 + android:layout_width="match_parent"
  53 + android:layout_height="match_parent">
  54 + </ListView>
  55 +
  56 + </LinearLayout>
  57 + </android.support.v4.widget.SwipeRefreshLayout>
  58 +
  59 + </android.support.constraint.ConstraintLayout>
  60 +
  61 +</android.support.constraint.ConstraintLayout>
  62 +
... ...
Risiko/app/src/main/res/layout/evaluationloglist.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="wrap_content"
  5 + android:layout_margin="20dp"
  6 + android:orientation="horizontal">
  7 +
  8 + <LinearLayout
  9 + android:layout_width="match_parent"
  10 + android:layout_height="wrap_content"
  11 + android:orientation="vertical">
  12 +
  13 + <LinearLayout
  14 + android:layout_width="match_parent"
  15 + android:layout_height="wrap_content"
  16 + android:orientation="horizontal">
  17 +
  18 + <TextView
  19 + android:layout_alignParentLeft="true"
  20 + android:id="@+id/tv_log_date"
  21 + android:layout_width="wrap_content"
  22 + android:layout_height="wrap_content"
  23 + android:layout_marginRight="10dp"
  24 + android:textSize="20dp"
  25 + android:text="Dato sist endret "/>
  26 +
  27 + <TextView
  28 + android:layout_alignParentLeft="true"
  29 + android:id="@+id/tv_log_name"
  30 + android:layout_width="wrap_content"
  31 + android:layout_height="wrap_content"
  32 + android:layout_marginBottom="10dp"
  33 + android:textSize="20dp"
  34 + android:text="Av: Ola Nordmann"/>
  35 +
  36 +
  37 + </LinearLayout>
  38 +
  39 + <TextView
  40 + android:layout_alignParentLeft="true"
  41 + android:id="@+id/tv_changed_fields"
  42 + android:layout_width="wrap_content"
  43 + android:layout_height="wrap_content"
  44 + android:layout_marginBottom="10dp"
  45 + android:textSize="20dp"
  46 + android:text="Felt som er endret"/>
  47 +
  48 + </LinearLayout>
  49 +
  50 +
  51 +
  52 +
  53 +
  54 +</RelativeLayout>
0 55 \ No newline at end of file
... ...
Risiko/app/src/main/res/layout/popup_evaluation.xml
... ... @@ -26,8 +26,7 @@
26 26 android:orientation="horizontal"
27 27 android:layout_width="fill_parent"
28 28 android:layout_height="match_parent"
29   - android:gravity="right|center"
30   - android:layout_marginRight="15dp">
  29 + android:gravity="right|center">
31 30  
32 31 <Button
33 32 android:layout_marginRight="15dp"
... ... @@ -36,6 +35,13 @@
36 35 android:layout_height="30dp"
37 36 android:background="@drawable/ic_edit"/>
38 37  
  38 + <Button
  39 + android:layout_marginRight="15dp"
  40 + android:id="@+id/pop_log"
  41 + android:layout_width="30dp"
  42 + android:layout_height="30dp"
  43 + android:background="@drawable/ic_eye_white"/>
  44 +
39 45 </LinearLayout>
40 46  
41 47 </LinearLayout>
... ...
restApi/.idea/workspace.xml
... ... @@ -2,10 +2,14 @@
2 2 <project version="4">
3 3 <component name="ChangeListManager">
4 4 <list default="true" id="0e20d303-9de8-4113-bfd9-019e72b304dc" name="Default" comment="">
5   - <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/EditEvaluation.java" />
6   - <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/layout/activity_edit_evaluation.xml" />
  5 + <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/EvaluationLog.java" />
  6 + <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/adapters/ListAdapterEvaluationLog.java" />
  7 + <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/dataclasses/EvaluationLog.java" />
  8 + <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/layout/activity_evaluation_log.xml" />
  9 + <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/layout/evaluationloglist.xml" />
7 10 <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/AndroidManifest.xml" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/AndroidManifest.xml" />
8   - <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" />
  11 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/EditEvaluation.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/EditEvaluation.java" />
  12 + <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
9 13 </list>
10 14 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
11 15 <option name="TRACKING_ENABLED" value="true" />
... ... @@ -53,7 +57,7 @@
53 57 <file leaf-file-name="routes.js" pinned="false" current-in-tab="true">
54 58 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
55 59 <provider selected="true" editor-type-id="text-editor">
56   - <state relative-caret-position="229">
  60 + <state relative-caret-position="4260">
57 61 <caret line="284" column="25" lean-forward="true" selection-start-line="284" selection-start-column="25" selection-end-line="284" selection-end-column="25" />
58 62 <folding />
59 63 </state>
... ... @@ -245,22 +249,21 @@
245 249 <workItem from="1541681303243" duration="9060000" />
246 250 <workItem from="1542189792461" duration="7537000" />
247 251 <workItem from="1542881688157" duration="372000" />
248   - <workItem from="1543226716067" duration="1107000" />
  252 + <workItem from="1543226716067" duration="1426000" />
249 253 </task>
250 254 <servers />
251 255 </component>
252 256 <component name="TimeTrackingManager">
253   - <option name="totallyTimeSpent" value="30798000" />
  257 + <option name="totallyTimeSpent" value="31117000" />
254 258 </component>
255 259 <component name="ToolWindowManager">
256 260 <frame x="0" y="0" width="1440" height="900" extended-state="6" />
257   - <editor active="true" />
258 261 <layout>
259 262 <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.20014094" sideWeight="0.69244605" order="0" side_tool="false" content_ui="combo" />
260 263 <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" />
261 264 <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" />
262 265 <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" />
263   - <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" />
  266 + <window_info id="Run" active="true" 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" />
264 267 <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" />
265 268 <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.30755395" order="2" side_tool="true" content_ui="tabs" />
266 269 <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" />
... ... @@ -369,7 +372,7 @@
369 372 </entry>
370 373 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
371 374 <provider selected="true" editor-type-id="text-editor">
372   - <state relative-caret-position="229">
  375 + <state relative-caret-position="4260">
373 376 <caret line="284" column="25" lean-forward="true" selection-start-line="284" selection-start-column="25" selection-end-line="284" selection-end-column="25" />
374 377 <folding />
375 378 </state>
... ...