Commit d86f749b90c62adf02c74bdba6361e2510f576c8

Authored by kristinlaahneolsen
1 parent 6929ee59

Nå loggføres det for hver gang noen er inne på en spesifikk hendelse. Igjen, vik…

…tig at vi lager sjekk på hvem som eier saken. + at vi må hente ut faktiske brukernavn og ikke bare hardkoding slik som nå
Risiko/app/src/main/java/activity/Accesslog.java
... ... @@ -33,8 +33,13 @@ public class Accesslog extends AppCompatActivity {
33 33 Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
34 34 setSupportActionBar(myToolbar);
35 35  
  36 + Intent intent = getIntent();
  37 + Bundle b = intent.getExtras();
  38 + String assosiatedincident = b.getString("associatedincitent");
  39 + System.out.println("ASSOSIATED INCIDENT" + assosiatedincident);
36 40  
37   - Api.get().getAccesslog("3caf2679-0ae3-4016-a8eb-39307a27c6fb").enqueue(new Callback<List<dataclasses.Accesslog>>() {
  41 +
  42 + Api.get().getAccesslog(assosiatedincident).enqueue(new Callback<List<dataclasses.Accesslog>>() {
38 43 @Override
39 44 public void onResponse(Call<List<dataclasses.Accesslog>> call, Response<List<dataclasses.Accesslog>> response) {
40 45 if (response.isSuccessful()) {
... ...
Risiko/app/src/main/java/activity/EditEvaluation.java
... ... @@ -80,7 +80,7 @@ public class EditEvaluation extends AppCompatActivity {
80 80 String newOutcome = etOutcome.getText().toString();
81 81 String newMeasures = etMeasures.getText().toString();
82 82  
83   - DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm");
  83 + DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm");
84 84 Date dateChanged = Calendar.getInstance().getTime();
85 85 String logDate = df.format(dateChanged);
86 86  
... ...
Risiko/app/src/main/java/activity/EvaluationLog.java
... ... @@ -38,7 +38,6 @@ public class EvaluationLog extends AppCompatActivity {
38 38 Intent intent = getIntent();
39 39 Bundle b = intent.getExtras();
40 40 String assosiatedeval = b.getString("assosiatedeval");
41   - System.out.println("ASSOSIATED EVAL" + assosiatedeval);
42 41 /*
43 42 List<dataclasses.EvaluationLog> log = new ArrayList<>();
44 43 log.add(new dataclasses.EvaluationLog("Ola Nordmann", "2015-02-02", "Alle", assosiatedeval));
... ...
Risiko/app/src/main/java/activity/Incident.java
... ... @@ -21,7 +21,11 @@ import com.risiko.risiko.R;
21 21  
22 22 import java.security.MessageDigest;
23 23 import java.security.NoSuchAlgorithmException;
  24 +import java.text.DateFormat;
  25 +import java.text.SimpleDateFormat;
24 26 import java.util.ArrayList;
  27 +import java.util.Calendar;
  28 +import java.util.Date;
25 29 import java.util.List;
26 30  
27 31 import adapters.ListAdapterIncidents;
... ... @@ -76,12 +80,28 @@ public class Incident extends AppCompatActivity {
76 80  
77 81  
78 82 private void insertEvents(List<dataclasses.Incident> incident) {
  83 + DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm");
  84 + Date dateLookedAt = Calendar.getInstance().getTime();
  85 + String logDate = df.format(dateLookedAt);
  86 +
79 87 lv = findViewById(R.id.lv_events);
80 88 lv.setAdapter(new ListAdapterIncidents(this, incident));
81 89 lv.setOnItemClickListener((parent, view, position, id) -> {
82 90 chosenEventId = ((dataclasses.Incident) lv.getItemAtPosition(position)).getId();
83 91 showEventPopup((dataclasses.Incident) lv.getItemAtPosition(position));
84 92  
  93 + Api.get().newAccesslogEntry(chosenEventId, "Pumba", 2, logDate).enqueue(new Callback<String>() {
  94 + @Override
  95 + public void onResponse(Call<String> call, Response<String> response) {
  96 +
  97 + }
  98 +
  99 + @Override
  100 + public void onFailure(Call<String> call, Throwable t) {
  101 +
  102 + }
  103 + });
  104 +
85 105 });
86 106 }
87 107  
... ... @@ -91,7 +111,6 @@ public class Incident extends AppCompatActivity {
91 111 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
92 112 alertDialogBuilder.setView(promptView);
93 113  
94   -
95 114 TextView tvTitle = promptView.findViewById(R.id.pop_headline);
96 115 TextView tvDate = promptView.findViewById(R.id.pop_date);
97 116 TextView tvLocation = promptView.findViewById(R.id.pop_place);
... ... @@ -101,29 +120,13 @@ public class Incident extends AppCompatActivity {
101 120 Button editEvent = promptView.findViewById(R.id.pop_edit_event);
102 121 Button seeLog = promptView.findViewById(R.id.btn_see_log);
103 122  
104   - //TODO TEST PÅ HASH
105   - MessageDigest md = null;
106   - try {
107   - md = MessageDigest.getInstance("SHA-512");
108   - } catch (NoSuchAlgorithmException e) {
109   - System.out.println("FEIL MED HASH ");
110   - }
111   - byte[] digest = md.digest(chosenItem.getDescription().getBytes());
112   - StringBuilder sb = new StringBuilder();
113   - for (int i = 0; i<digest.length; i++) {
114   - sb.append(Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1));
115   - }
116   - System.out.println("SUKSESS MED HASH" + sb);
117   -
118   -
119 123 //TODO: IMPLEMENTERE DET SLIK AT VI FÅR HENTET UT HVILKEN BRUKER SOM HAR SKREVET SAKEN
120 124 TextView addedBy = promptView.findViewById(R.id.tv_added_by);
121 125  
122 126 deleteEvent.setOnClickListener(view -> deleteEventDialog());
123 127 editEvent.setOnClickListener(view -> editIncident(chosenItem.getId(), chosenItem.getTitle(), chosenItem.getDate(), chosenItem.getDescription(), chosenItem.getLocation(), chosenItem.getAssociatedeval()));
124   - seeLog.setOnClickListener(view -> startActivity(new Intent(this, Accesslog.class)));
  128 + seeLog.setOnClickListener(view -> goToAccesslog(chosenEventId));
125 129  
126   - System.out.println("EVALID" + chosenItem.getAssociatedeval());
127 130 Api.get().getEvaluation(chosenItem.getAssociatedeval()).enqueue(new Callback<Evaluation>() {
128 131 @Override
129 132 public void onResponse(Call<Evaluation> call, Response<Evaluation> response) {
... ... @@ -134,15 +137,12 @@ public class Incident extends AppCompatActivity {
134 137  
135 138 @Override
136 139 public void onFailure(Call<Evaluation> call, Throwable t) {
137   - System.out.println("FEILAAA");
  140 + t.printStackTrace();
138 141  
139 142 }
140 143 });
141 144  
142 145  
143   -
144   -
145   -
146 146 tvTitle.setText(chosenItem.getTitle());
147 147 tvDate.setText(chosenItem.getDate());
148 148 tvLocation.setText(chosenItem.getLocation());
... ... @@ -160,8 +160,8 @@ public class Incident extends AppCompatActivity {
160 160 }
161 161  
162 162 private void goToAccesslog(String id) {
163   - Intent intentLog = new Intent(this, Log.class);
164   - //intentLog.putExtra("associatedincitent", id);
  163 + Intent intentLog = new Intent(this, Accesslog.class);
  164 + intentLog.putExtra("associatedincitent", id);
165 165 startActivity(intentLog);
166 166 }
167 167  
... ...
Risiko/app/src/main/java/api/Endpoints.java
... ... @@ -90,4 +90,8 @@ public interface Endpoints {
90 90 @GET("/incident/{associatedincident}/accesslog")
91 91 Call<List<Accesslog>> getAccesslog(@Path("associatedincident") String associatedincident);
92 92  
  93 + @FormUrlEncoded
  94 + @POST("accesslog")
  95 + Call<String> newAccesslogEntry(@Field("associatedincident") String associatedincident, @Field("name") String name, @Field("groupnr") int groupnr, @Field("date") String date);
  96 +
93 97 }
... ...
Risiko/app/src/main/res/layout/popup_event.xml
... ... @@ -150,7 +150,7 @@
150 150 android:background="@color/colorLightGray"
151 151 android:layout_width="200dp"
152 152 android:layout_height="wrap_content"
153   - android:text="@string/see_log"/>
  153 + android:text="@string/accesss_log"/>
154 154  
155 155  
156 156 </LinearLayout>
157 157 \ No newline at end of file
... ...
Risiko/app/src/main/res/values/strings.xml
... ... @@ -41,6 +41,7 @@
41 41 <string name="added_by">Lagt til av:</string>
42 42 <string name="see_log">Se hendelseslogg</string>
43 43 <string name="aksesslogg">Aksesslogg</string>
  44 + <string name="accesss_log">Se tilgangslogg</string>
44 45  
45 46  
46 47 </resources>
... ...