Skip to content

feature #87853 feat: Hackathon - Implement create new article page us… #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions code/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,2 @@
<!--The content below is only a placeholder and can be replaced.-->
<div style="text-align:center">
<h1>
Welcome to {{title}}!
</h1>
<img width="300" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxOS4xLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJIHZpZXdCb3g9IjAgMCAyNTAgMjUwIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAyNTAgMjUwOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPg0KCS5zdDB7ZmlsbDojREQwMDMxO30NCgkuc3Qxe2ZpbGw6I0MzMDAyRjt9DQoJLnN0MntmaWxsOiNGRkZGRkY7fQ0KPC9zdHlsZT4NCjxnPg0KCTxwb2x5Z29uIGNsYXNzPSJzdDAiIHBvaW50cz0iMTI1LDMwIDEyNSwzMCAxMjUsMzAgMzEuOSw2My4yIDQ2LjEsMTg2LjMgMTI1LDIzMCAxMjUsMjMwIDEyNSwyMzAgMjAzLjksMTg2LjMgMjE4LjEsNjMuMiAJIi8+DQoJPHBvbHlnb24gY2xhc3M9InN0MSIgcG9pbnRzPSIxMjUsMzAgMTI1LDUyLjIgMTI1LDUyLjEgMTI1LDE1My40IDEyNSwxNTMuNCAxMjUsMjMwIDEyNSwyMzAgMjAzLjksMTg2LjMgMjE4LjEsNjMuMiAxMjUsMzAgCSIvPg0KCTxwYXRoIGNsYXNzPSJzdDIiIGQ9Ik0xMjUsNTIuMUw2Ni44LDE4Mi42aDBoMjEuN2gwbDExLjctMjkuMmg0OS40bDExLjcsMjkuMmgwaDIxLjdoMEwxMjUsNTIuMUwxMjUsNTIuMUwxMjUsNTIuMUwxMjUsNTIuMQ0KCQlMMTI1LDUyLjF6IE0xNDIsMTM1LjRIMTA4bDE3LTQwLjlMMTQyLDEzNS40eiIvPg0KPC9nPg0KPC9zdmc+DQo=">
</div>
<h2>Here are some links to help you start: </h2>
<ul>
<li>
<h2><a target="_blank" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
</li>
<li>
<h2><a target="_blank" href="https://github.com/angular/angular-cli/wiki">CLI Documentation</a></h2>
</li>
<li>
<h2><a target="_blank" href="https://blog.angular.io//">Angular blog</a></h2>
</li>
</ul>
<app-new-article></app-new-article>

5 changes: 0 additions & 5 deletions code/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { TestBed, async } from '@angular/core/testing';

import { AppComponent } from './app.component';

describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion code/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import { Component } from '@angular/core';
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';

}
15 changes: 10 additions & 5 deletions code/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -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 { }
15 changes: 15 additions & 0 deletions code/src/app/mycountry.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
}));
});
24 changes: 24 additions & 0 deletions code/src/app/mycountry.service.ts
Original file line number Diff line number Diff line change
@@ -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');
});
}

}
15 changes: 15 additions & 0 deletions code/src/app/new-article/new-article.component.css
Original file line number Diff line number Diff line change
@@ -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;
}
39 changes: 39 additions & 0 deletions code/src/app/new-article/new-article.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<h2 class="nav">Create Article</h2>
<form (ngSubmit)="onSubmit()" class="form-lay" [formGroup]="articleForm" novalidate>
<div class="form-group">
<h4 class="center-block"> Article title:
<input class="form-control" formControlName="title">
</h4>
</div>
<div class="form-group">
<h4 class="center-block">Intro text:
<input class="form-control" formControlName="introtext">
</h4>
</div>
<div class="form-group">
<h4 class="center-block">Full text:
<input class="form-control" formControlName="fulltext">
</h4>
</div>
<div class="form-group">
<h4 class="center-block">Category :
<select class="form-control" formControlName="cat">
<option *ngFor="let cat of categories" [value]="cat.id">{{cat.title}}</option>
</select>
</h4>
</div>
<div class="form-group">
<h4 class="center-block">Start publishing :
<input data-format="MM/dd/yyyy HH:mm:ss PP" type="date" class="form-control" formControlName="publishup">
</h4>
</div>
<div class="form-group">
<h4 class="center-block">Finish publishing :
<input type="date" class="form-control" formControlName="publishdown">
</h4>
</div>

<input class="save form-control" type="submit">


</form>
25 changes: 25 additions & 0 deletions code/src/app/new-article/new-article.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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<NewArticleComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ NewArticleComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(NewArticleComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
49 changes: 49 additions & 0 deletions code/src/app/new-article/new-article.component.ts
Original file line number Diff line number Diff line change
@@ -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() {
}

}