<commit_before>import { Inject } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import {ActivatedRoute} from "@angular/router";


import {
  UserService,
  AuthService,
  ProductService,
  ConfigService
} from '../service';

import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import 'rxjs/add/observable/interval';

@Component({
  selector: 'app-product',
  templateUrl: './product.component.html',
  styleUrls: ['./product.component.scss']
})
export class ProductComponent implements OnInit {
  title = 'Create Product';
  form: FormGroup;

  /**
   * Boolean used in telling the UI
   * that the form has been submitted
   * and is awaiting a response
   */
  submitted = false;

  /**
   * Diagnostic message from received
   * form request error
   */
  errorDiagnostic: string;
  productNotFound: string;
  successMessage: string;
  product:any;
  productTypes:any[] = [];
  btnText = 'Create';
  isUpdate = false;
  prodId:any;
  constructor(
    private userService: UserService,
    private authService: AuthService,
    private productService: ProductService,
    private router: Router,
    private formBuilder: FormBuilder,
    private route: ActivatedRoute,
    private config:ConfigService
  ) {
    this.route.params.subscribe( params => {
      console.log(params);
      if (params['id']) { 
        this.btnText = 'Update';
        this.isUpdate = true;
        this.prodId = params['id'];
        this.loadProduct(params['id'])
      }
    });
    this.loadProductTypes();
  }

  ngOnInit() {
    this.product = {
      name: "test",
      type:this.productTypes
    }
    if(!this.userService.currentUser) {
      this.router.navigate(['/login']);
    }
    this.form = this.formBuilder.group({
      productname: ['', Validators.compose([Validators.required, Validators.minLength(3), Validators.maxLength(64)])],
      description: ['', Validators.compose([Validators.required, Validators.minLength(3), Validators.maxLength(32)])],
      type: [''],
      image: ['', Validators.compose([Validators.required, Validators.minLength(3), Validators.maxLength(32)])],
      size: [''],
      category: ['', Validators.compose([Validators.required, Validators.minLength(3), Validators.maxLength(32)])],
      height: [''],
      weight: [''],
      metalType: [''],
      gem:[''],
      sellingPrice: [''],
      actualPrice: [''],
      soldOut:[''],
      toRestock: [''],
      quantity:['']
    });

  }

  onSubmit() {
    /**
     * Innocent until proven guilty
     */
    this.submitted = true;
    this.errorDiagnostic = null;
    this.successMessage = null;
    if(this.isUpdate) {
    this.productService.updateProduct(this.prodId, this.form.value)
    .subscribe(data => {
      console.log(data.data);
      this.config.saveData("Product updated successfully");
      this.router.navigate(['/']);
    },
    error => {
      console.log(error.status);
      this.submitted = false;
      if(error.status == 403) {
        this.errorDiagnostic = 'Please login as admin to create product';
      } else {
        this.errorDiagnostic = 'Error occured while creating product. Please try again later.';
      }
    });
    } 
  else {
    this.productService.createProduct(this.form.value)
    .subscribe(data => {
      console.log(data.data);
      this.config.saveData("Product created successfully");
      this.router.navigate(['/']);
    },
    error => {
      console.log(error.status);
      this.submitted = false;
      if(error.status == 403) {
        this.errorDiagnostic = 'Please login as admin to update product';
      } else {
        this.errorDiagnostic = 'Error occured while updating product. Please try again later.';
      }
    });
  }
    
<commit_msg>Updated response message for product creation<commit_after>import { Inject } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import {ActivatedRoute} from "@angular/router";


import {
  UserService,
  AuthService,
  ProductService,
  ConfigService
} from '../service';

import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import 'rxjs/add/observable/interval';

@Component({
  selector: 'app-product',
  templateUrl: './product.component.html',
  styleUrls: ['./product.component.scss']
})
export class ProductComponent implements OnInit {
  title = 'Create Product';
  form: FormGroup;

  /**
   * Boolean used in telling the UI
   * that the form has been submitted
   * and is awaiting a response
   */
  submitted = false;

  /**
   * Diagnostic message from received
   * form request error
   */
  errorDiagnostic: string;
  productNotFound: string;
  successMessage: string;
  product:any;
  productTypes:any[] = [];
  btnText = 'Create';
  isUpdate = false;
  prodId:any;
  constructor(
    private userService: UserService,
    private authService: AuthService,
    private productService: ProductService,
    private router: Router,
    private formBuilder: FormBuilder,
    private route: ActivatedRoute,
    private config:ConfigService
  ) {
    this.route.params.subscribe( params => {
      console.log(params);
      if (params['id']) { 
        this.btnText = 'Update';
        this.isUpdate = true;
        this.prodId = params['id'];
        this.loadProduct(params['id'])
      }
    });
    this.loadProductTypes();
  }

  ngOnInit() {
    this.product = {
      name: "test",
      type:this.productTypes
    }
    if(!this.userService.currentUser) {
      this.router.navigate(['/login']);
    }
    this.form = this.formBuilder.group({
      productname: ['', Validators.compose([Validators.required, Validators.minLength(3), Validators.maxLength(64)])],
      description: ['', Validators.compose([Validators.required, Validators.minLength(3), Validators.maxLength(32)])],
      type: [''],
      image: ['', Validators.compose([Validators.required, Validators.minLength(3), Validators.maxLength(32)])],
      size: [''],
      category: ['', Validators.compose([Validators.required, Validators.minLength(3), Validators.maxLength(32)])],
      height: [''],
      weight: [''],
      metalType: [''],
      gem:[''],
      sellingPrice: [''],
      actualPrice: [''],
      soldOut:[''],
      toRestock: [''],
      quantity:['']
    });

  }

  onSubmit() {
    /**
     * Innocent until proven guilty
     */
    this.submitted = true;
    this.errorDiagnostic = null;
    this.successMessage = null;
    if(this.isUpdate) {
    this.productService.updateProduct(this.prodId, this.form.value)
    .subscribe(data => {
      console.log(data.data);
      this.config.saveData("Product updated successfully");
      this.router.navigate(['/']);
    },
    error => {
      console.log(error.status);
      this.submitted = false;
      if(error.status == 403) {
        this.errorDiagnostic = 'Please login as admin to create product';
      } else {
        this.errorDiagnostic = 'Error occured while creating product. Please try again later.';
      }
    });
    } 
  else {
    this.productService.createProduct(this.form.value)
    .subscribe(data => {
      console.log(data.data);
      this.config.saveData("Product created successfully with id : "+data.data);
      this.router.navigate(['/']);
    },
    error => {
      console.log(error.status);
      this.submitted = false;
      if(error.status == 403) {
        this.errorDiagnostic = 'Please login as admin to update product';
      } else {
        this.errorDiagnostic = 'Error occured while updating product. Please try again later.';
      }
    });
  }
    

{'fraction_non_alphanumeric': 0.1448293493544676, 'fraction_numerical': 0.0046018151604243895, 'mean_word_length': 3.0061443932411676, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '244131', 'n_tokens_mistral': 2359, 'n_tokens_neox': 2322, 'n_words': 496}