<commit_before>import { Component } from '@angular/core';
import {Forum} from "./forum";
import {ForumOwner} from "./forum-owner";

import { Headers, Http, RequestOptions } from '@angular/http';

import 'rxjs/add/operator/toPromise';


@Component({
  moduleId: module.id,
  selector: 'create-forum',
  template: `    
    <h2>{{pageTitle}}</h2>
    <div class="container">
    <form (submit)="addForum(
        title.value,
        owner.value,
        categories.value
    )">
      <div class="form-group">
        <label for="title">Titel</label>
        <input #title type="text" class="form-control" required>
      </div>
      <div class="form-group">
        <label for="owner">Owner</label>
        <input #owner type="text" class="form-control" required>
      </div>
      <div class="form-group">
        <label for="categories">Kategorien</label>
        <input #categories type="text" class="form-control">
      </div>
      <button type="submit" class="btn btn-default">Submit</button>
    </form>
    </div>
  `,
})
export class CreateForumComponent {

  pageTitle="Forum erstellen";
  submitted = false;
  //onSubmit() { this.submitted = true; }

  id: string;
  title: string;
  owner: string;
  categories: string[];
  forum: Forum;

  private apiUrl = 'http://localhost:8180/api/rt';  // URL to web api
  constructor (private http: Http){};


  // TODO: Remove this when we're done
  //get diagnostic() { return JSON.stringify(this.model); }

  //constructor(private heroService: HeroService) { }

  addForum(title: string, owner: string, categories?: string): void {

    this.title = title;
    this.owner = owner;
    if(categories){
      this.categories = categories.split(",");
    }
    else{
      this.categories = ["noch keine Kategorie"]
    }

    this.createNewForum()
      .then(id => this.updateNewForum(id));

    this.submitted = true;
  };

  createNewForum(): Promise<string> {
    return this.http.post(this.apiUrl,"test")
      .toPromise()
      .then(response => response.json().id)
      .catch(this.handleError);
  }

  updateNewForum(id: string): Promise<Forum> {
    let headers = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({ headers: headers });
    console.log("id: "+ id);
    this.id = id;
    const url = `${this.apiUrl}/${id}`;
    return this.http.put(url,{"title":this.title,"owner":this.owner, "categories":this.categories},options)
      .toPromise()
      .then(response => response.json())
      .catch(this.handleError);
  }

  private handleError(error: any): Promise<any> {
    console.error('An error occurred', error); // for demo purposes only
    return Promise.reject(error.message || error);
  }

}
<commit_msg>create forum by filling the form and save to database ToDo: put saving/updating functionality into dedicated service<commit_after>import { Component } from '@angular/core';
import {Forum} from "./forum";
import {ForumOwner} from "./forum-owner";

import { Headers, Http, RequestOptions } from '@angular/http';

import 'rxjs/add/operator/toPromise';


@Component({
  moduleId: module.id,
  selector: 'create-forum',
  template: `    
    <h2>{{pageTitle}}</h2>
    <div class="container">
    <form (submit)="addForum(
        title.value,
        owner.value,
        categories.value
    )">
      <div class="form-group">
        <label for="title">Titel</label>
        <input #title type="text" class="form-control" required>
      </div>
      <div class="form-group">
        <label for="owner">Owner</label>
        <input #owner type="text" class="form-control" required>
      </div>
      <div class="form-group">
        <label for="categories">Kategorien</label>
        <input #categories type="text" class="form-control">
      </div>
      <button type="submit" class="btn btn-default">Submit</button>
    </form>
    </div>
  `,
})
export class CreateForumComponent {

  pageTitle="Forum erstellen";
  submitted = false;
  //onSubmit() { this.submitted = true; }

  id: string;
  title: string;
  owner: string;
  categories: string[];
  forum: Forum;

  private apiUrl = 'http://localhost:8180/api/rt';  // URL to web api
  constructor (private http: Http){};


  // TODO: Remove this when we're done
  //get diagnostic() { return JSON.stringify(this.model); }

  //constructor(private heroService: HeroService) { }

  addForum(title: string, owner: string, categories?: string): void {

    this.title = title;
    this.owner = owner;
    if(categories){
      this.categories = categories.split(",");
    }
    else{
      this.categories = ["noch keine Kategorie"]
    }

    this.createNewForum()
      .then(id => this.updateNewForum(id));

    this.submitted = true;
  };

  createNewForum(): Promise<string> {
    return this.http.post(this.apiUrl,"test")
      .toPromise()
      .then(response => response.json().id)
      .catch(this.handleError);
  }

  updateNewForum(id: string): Promise<Forum> {

    let headers = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({ headers: headers });
    console.log("id: "+ id);
    this.id = id;
    const url = `${this.apiUrl}/${id}`;

    return this.http.put(url,{"title":this.title,"owner":this.owner, "categories":this.categories},options)
      .toPromise()
      .then(response => response.json())
      .catch(this.handleError);
  }

  private handleError(error: any): Promise<any> {
    console.error('An error occurred', error); // for demo purposes only
    return Promise.reject(error.message || error);
  }

}

{'fraction_non_alphanumeric': 0.1629203380686927, 'fraction_numerical': 0.002157885272433016, 'mean_word_length': 3.163173652694611, 'pattern_counts': {'":': 6, '<': 55, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6692370', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1719, 'n_words': 394}