Commit c696c02e authored by Wosiek, Oliver's avatar Wosiek, Oliver
Browse files

funktioniert leider nicht

(user == null)
parent 8deed183
Pipeline #7587 passed with stage
in 9 minutes and 5 seconds
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css');
.form-control {
margin:5px;
width: 97%;
float: left;
}
#noteplain{
resize: none;
background-color: #C9D1C8;
border: none;
}
#note{
resize: none;
}
#stern{
margin:6px;
font-size: 12px;
}
#delete {
color: red;
}
.invalid-feedback {
margin:6px;
}
label {
width: 100%;
}
import 'package:angular/angular.dart';
import 'package:angular_forms/angular_forms.dart';
import 'package:angular_router/angular_router.dart';
import 'package:demo/src/model/person.dart';
import 'package:demo/src/view/routes/route_paths.dart';
import 'package:demo/src/view/services/person_service.dart';
import 'package:demo/src/view/components/login_component.dart';
@Component(
selector: 'account',
templateUrl: 'account_component.html',
styleUrls: ['account_component.css'],
directives: [coreDirectives, routerDirectives, formDirectives],
)
/// Klasse zur verwaltung der Termine
class AccountComponent implements OnActivate {
AccountComponent(this._userService, this._location, this._router);
User user;
final Location _location;
bool deleteControl = false;
final Router _router;
final UserService _userService;
/// Folgender Code wird immer bei der Aktivierung der Klasse aufgerufen
@override
void onActivate(_, RouterState current) async {
if (!LoginComponent.loggedIn) {
await _router.navigate('/login');
} else {
final cc = getNumber(current.parameters);
print(current.parameters);
if (cc != null) {
user = await _userService.get(cc);
}
}
}
/// Methode zum speichern der Änderungen, die man am User vorgenommen hat
Future<void> save() async {
await _userService.update(user);
}
///Methode zum löschen von Terminen
Future<void> delete() async {
if (deleteControl==true) {
await _userService.delete(user.username);
goBack();
} else {
deleteControl = true;
}
}
///Methode, die die übergeordnete Ansicht anzeigt
void goBack() => _location.back();
}
\ No newline at end of file
<div *ngIf="user != null">
<h3>{{user.username}}</h3>
</div>
\ No newline at end of file
......@@ -18,6 +18,9 @@
<li [routerLink]="RoutePaths.contacts.toUrl()"
[routerLinkActive]="'active'">Contacts
</li>
<li [routerLink]="RoutePaths.account.toUrl()"
[routerLinkActive]="'active'">Account
</li>
<li (click)="logout()" [routerLink]="RoutePaths.login.toUrl()">Logout</li>
</nav>
......
......@@ -17,6 +17,7 @@ class RoutePaths {
static final RoutePath dayview = RoutePath(path: '${calendarMain.path}/:$yParam/:$mParam/:$dParam');
static final RoutePath register = RoutePath(path: 'register');
static final RoutePath login = RoutePath(path: 'login');
static final RoutePath account = RoutePath(path: 'account');
static final RoutePath contacts = RoutePath(path: 'contacts');
static final RoutePath contact = RoutePath(path: '${contacts.path}/:$conParam');
......
import 'package:angular/angular.dart';
import 'package:angular/core.dart';
import 'package:angular_router/angular_router.dart';
import '../components/account_component.template.dart' as account_template;
import '../components/appointment_component.template.dart' as appointment_template;
import '../components/appointment_list_component.template.dart' as appointment_list_template;
import '../components/appointment_new_component.template.dart' as appointment_new_template;
......@@ -65,6 +66,10 @@ class Routes {
routePath: RoutePaths.contact,
component: contact_template.ContactComponentNgFactory as ComponentFactory,
);
static final RouteDefinition account = RouteDefinition(
routePath: RoutePaths.account,
component: account_template.AccountComponentNgFactory as ComponentFactory,
);
// routing auf diese Component
static final List<RouteDefinition> all = <RouteDefinition>[
dashboard,
......@@ -78,6 +83,7 @@ class Routes {
contact,
register,
login,
account,
RouteDefinition.redirect(
path: '',
redirectTo: RoutePaths.login.toUrl(),
......
import 'dart:async';
import 'dart:convert';
import 'dart:html';
import 'package:demo/src/view/main_component.dart';
import 'package:http/http.dart';
import 'package:demo/src/model/person.dart';
......@@ -8,19 +9,25 @@ class UserService {
// request to middlemand
UserService(this._http);
static final _headers = {'Content-Type': 'application/json'};
//static final _headers = {'Content-Type': 'application/json'};
static const _userUrl = host + '/user'; // URL to web API
final Client _http;
static const _type = MapEntry('Content-Type', 'application/json');
// getter for the Authorization
Map<String,String> get _headers => Map.fromEntries(
[MapEntry("Authorization", "$_tokenType $_tokenAuth"), _type]);
String get _tokenType => window.localStorage["token_type"];
String get _tokenAuth => window.localStorage["access_token"];
///Liest die Daten aus einer Response
dynamic _extractData(Response resp) => json.decode(resp.body);
Exception _handleError(dynamic e) {
print(e); // for demo purposes only
return Exception('Server error; cause: $e');
}
///Erstellt einen neuen User mit gegebenem Namen, Email und Passwort
///Erstellt einen neuen User
Future<User> create(User user) async {
try {
final response = await _http.post(_userUrl,
......@@ -32,6 +39,22 @@ class UserService {
}
}
///Updatet einen bereits existierenden User
Future<User> update(User user) async {
// Add security Header
final Response response = await _http.put(_userUrl,
headers: _headers, body: json.encode(user.toJson())) as Response;
return User.fromJson(
_extractData(response as Response) as Map<String, dynamic>);
}
///Löscht den User mit gegebenem contactCode
Future<void> delete(String contactCode) async {
// Add security Header
final url = '$_userUrl/$contactCode';
await _http.delete(url, headers: _headers);
}
Future<List<User>> getAll() async {
final Response response = await _http.get('$_userUrl') as Response;
return (_extractData(response) as List)
......@@ -44,5 +67,4 @@ class UserService {
await _http.get('$_userUrl/$contactCode') as Response;
return User.fromJson(_extractData(response) as Map<String, dynamic>);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment