diff --git a/code/src/app/app.component.html b/code/src/app/app.component.html index 230f4ed..156d372 100644 --- a/code/src/app/app.component.html +++ b/code/src/app/app.component.html @@ -1,20 +1,2 @@ - -
-

- Welcome to {{title}}! -

- -
-

Here are some links to help you start:

- + diff --git a/code/src/app/app.component.spec.ts b/code/src/app/app.component.spec.ts index 9510495..bcbdf36 100644 --- a/code/src/app/app.component.spec.ts +++ b/code/src/app/app.component.spec.ts @@ -1,7 +1,5 @@ import { TestBed, async } from '@angular/core/testing'; - import { AppComponent } from './app.component'; - describe('AppComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ @@ -10,19 +8,16 @@ describe('AppComponent', () => { ], }).compileComponents(); })); - it('should create the app', async(() => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; expect(app).toBeTruthy(); })); - it(`should have as title 'app'`, async(() => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; expect(app.title).toEqual('app'); })); - it('should render title in a h1 tag', async(() => { const fixture = TestBed.createComponent(AppComponent); fixture.detectChanges(); diff --git a/code/src/app/app.component.ts b/code/src/app/app.component.ts index 7b0f672..d61ff95 100644 --- a/code/src/app/app.component.ts +++ b/code/src/app/app.component.ts @@ -6,5 +6,5 @@ import { Component } from '@angular/core'; styleUrls: ['./app.component.css'] }) export class AppComponent { - title = 'app'; + } diff --git a/code/src/app/app.module.ts b/code/src/app/app.module.ts index f657163..1d5e6b8 100644 --- a/code/src/app/app.module.ts +++ b/code/src/app/app.module.ts @@ -1,16 +1,21 @@ import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; - +import { Http, HttpModule } from '@angular/http'; import { AppComponent } from './app.component'; - +import { MycountryService } from "./mycountry.service"; +import { NewArticleComponent } from './new-article/new-article.component' +import { ReactiveFormsModule } from '@angular/forms'; @NgModule({ declarations: [ - AppComponent + AppComponent, + NewArticleComponent ], imports: [ - BrowserModule + BrowserModule, + HttpModule, + ReactiveFormsModule ], - providers: [], + providers: [MycountryService], bootstrap: [AppComponent] }) export class AppModule { } diff --git a/code/src/app/mycountry.service.spec.ts b/code/src/app/mycountry.service.spec.ts new file mode 100644 index 0000000..30cad23 --- /dev/null +++ b/code/src/app/mycountry.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { MycountryService } from './mycountry.service'; + +describe('MycountryService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [MycountryService] + }); + }); + + it('should be created', inject([MycountryService], (service: MycountryService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/code/src/app/mycountry.service.ts b/code/src/app/mycountry.service.ts new file mode 100644 index 0000000..36b3a4b --- /dev/null +++ b/code/src/app/mycountry.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@angular/core'; +import { Http, Headers} from '@angular/http' +@Injectable() +export class MycountryService { + constructor(private http : Http) { } + + getCat(){ + let url = 'https://hackathondemo.cloudaccess.host/index.php?option=com_api&app=categories&resource=categories&format=raw&lang=en&key=d5d2e3fa64391f11b57a2d16ad67da33'; + return this.http.get(url); + } + + postArticle(url, data){ + let headers = new Headers(); + headers.append('Content-Type', 'application/x-www-form-urlencoded'); + + this.http.post(url, data, { + headers: headers + }).subscribe(data => { + if (data.json().data.success) + alert('Article created Successfully'); + }); + } + +} diff --git a/code/src/app/new-article/new-article.component.css b/code/src/app/new-article/new-article.component.css new file mode 100644 index 0000000..68cf340 --- /dev/null +++ b/code/src/app/new-article/new-article.component.css @@ -0,0 +1,15 @@ +.nav { + background-color: #43A7FE; + color: white; + margin-top:0px; + padding: 5px; + text-align: center; +} +.save { + background-color: #43A7FE; + color: white; +} + +.form-lay{ + padding: 5px; +} \ No newline at end of file diff --git a/code/src/app/new-article/new-article.component.html b/code/src/app/new-article/new-article.component.html new file mode 100644 index 0000000..ea80855 --- /dev/null +++ b/code/src/app/new-article/new-article.component.html @@ -0,0 +1,39 @@ + +
+
+

Article title: + +

+
+
+

Intro text: + +

+
+
+

Full text: + +

+
+
+

Category : + +

+
+
+

Start publishing : + +

+
+
+

Finish publishing : + +

+
+ + + + +
\ No newline at end of file diff --git a/code/src/app/new-article/new-article.component.spec.ts b/code/src/app/new-article/new-article.component.spec.ts new file mode 100644 index 0000000..76c0b16 --- /dev/null +++ b/code/src/app/new-article/new-article.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { NewArticleComponent } from './new-article.component'; + +describe('NewArticleComponent', () => { + let component: NewArticleComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ NewArticleComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(NewArticleComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/code/src/app/new-article/new-article.component.ts b/code/src/app/new-article/new-article.component.ts new file mode 100644 index 0000000..4da89d1 --- /dev/null +++ b/code/src/app/new-article/new-article.component.ts @@ -0,0 +1,49 @@ +import { Component, OnInit } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { MycountryService } from '../mycountry.service'; +@Component({ + selector: 'app-new-article', + templateUrl: './new-article.component.html', + styleUrls: ['./new-article.component.css'] +}) +export class NewArticleComponent implements OnInit { + articleForm: FormGroup; + categories; + + constructor(private fb: FormBuilder, private mydata: MycountryService, private http: Http) { + this.articleForm = this.fb.group({ + title: ['', Validators.required], + introtext: ['', Validators.required], + fulltext: '', + cat: ['', Validators.required], + publishup: '', + publishdown: '' + }); + + this.getArticle(); + } + + getArticle() { + this.mydata.getCat().subscribe(data => { + this.categories = data.json().data; + }); + } + + onSubmit() { + if (!this.articleForm.value.title) + alert('Please enter the article title'); + else if (!this.articleForm.value.introtext) + alert('Please enter the Into test'); + else if (!this.articleForm.value.cat) + alert('Please select category'); + else { + let url = 'https://hackathondemo.cloudaccess.host/index.php?option=com_api&app=articles&resource=article&key=d5d2e3fa64391f11b57a2d16ad67da33&format=raw'; + let data = '&title=' + this.articleForm.value.title + '&introtext=' + this.articleForm.value.introtext + '&fulltext=' + this.articleForm.value.fulltext + '&state=1&catid=' + this.articleForm.value.cat + '&publish_up=' + this.articleForm.value.publishup + '&publish_down=' + this.articleForm.value.publishdown; + this.mydata.postArticle(url, data); + } + } + + ngOnInit() { + } + +}