Skip to content

Commit

Permalink
Set all model properties to undefined to make sure the changeAware de…
Browse files Browse the repository at this point in the history
…corator picks them up, added default status to articles table
  • Loading branch information
zakhenry committed Aug 10, 2015
1 parent 699fed1 commit 8e94128
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 31 deletions.
Expand Up @@ -16,7 +16,7 @@ public function up()
Schema::create(Article::getTableName(), function (Blueprint $table) {
$table->uuid('article_id')->primary();
$table->string('title', 255);
$table->enum('status', Article::$statuses);
$table->enum('status', Article::$statuses)->default(Article::STATUS_DRAFT);
$table->text('content');
$table->text('excerpt')->nullable();
$table->string('primary_image')->nullable();
Expand Down
12 changes: 6 additions & 6 deletions app/src/common/models/article/articleModel.ts
Expand Up @@ -3,12 +3,12 @@ namespace common.models {
@common.decorators.changeAware
export class Article extends AbstractModel{

public articleId:string;
public title:string;
public permalink:string;
public content:string;
public primaryImage:string;
public status:string;
public articleId:string = undefined;
public title:string = undefined;
public permalink:string = undefined;
public content:string = undefined;
public primaryImage:string = undefined;
public status:string = undefined;

constructor(data:any) {

Expand Down
22 changes: 11 additions & 11 deletions app/src/common/models/user/userModel.ts
Expand Up @@ -7,17 +7,17 @@ namespace common.models {
public static guestType = 'guest';
public static userTypes:string[] = [User.adminType, User.guestType];

public userId:string;
public email:string;
public firstName:string;
public lastName:string;
public emailConfirmed:string;
public country:string;
public avatarImgUrl:string;
public timezoneIdentifier:string;
public _userCredential:global.IUserCredential;
public _userProfile:common.models.UserProfile;
public userType:string;
public userId:string = undefined;
public email:string = undefined;
public firstName:string = undefined;
public lastName:string = undefined;
public emailConfirmed:string = undefined;
public country:string = undefined;
public avatarImgUrl:string = undefined;
public timezoneIdentifier:string = undefined;
public _userCredential:global.IUserCredential = undefined;
public _userProfile:common.models.UserProfile = undefined;
public userType:string = undefined;

constructor(data:global.IUserData) {
super(data);
Expand Down
20 changes: 10 additions & 10 deletions app/src/common/models/user/userProfileModel.ts
Expand Up @@ -6,16 +6,16 @@ module common.models {

export class UserProfile implements IModel {

public dob:string;
public mobile:string;
public phone:string;
public gender:string;
public about:string;
public facebook:string;
public twitter:string;
public pinterest:string;
public instagram:string;
public website:string;
public dob:string = undefined;
public mobile:string = undefined;
public phone:string = undefined;
public gender:string = undefined;
public about:string = undefined;
public facebook:string = undefined;
public twitter:string = undefined;
public pinterest:string = undefined;
public instagram:string = undefined;
public website:string = undefined;

public static genderOptions:IGenderOption[] = [
{label: 'Male', value: 'M'},
Expand Down
9 changes: 6 additions & 3 deletions app/src/common/services/article/articleService.ts
Expand Up @@ -64,14 +64,17 @@ namespace common.services.article {
* Save the article
* @param article
* @param newArticle
* @returns {any}
* @returns ng.IPromise<common.models.Article>
*/
public saveArticle(article:common.models.Article, newArticle:boolean = false){
public saveArticle(article:common.models.Article, newArticle:boolean = false):ng.IPromise<common.models.Article>{

let method = newArticle? 'put' : 'patch';

return this.ngRestAdapter[method]('/articles/'+article.articleId, (<common.decorators.IChangeAwareDecorator>article).getChanged())
.then((res) => article);
.then((res) => {
(<common.decorators.IChangeAwareDecorator>article).resetChangedProperties(); //reset so next save only saves the changed ones
return article;
});

}

Expand Down

0 comments on commit 8e94128

Please sign in to comment.