-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/529talp'
- Loading branch information
Showing
8 changed files
with
445 additions
and
29 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
altrpnjs/app/Controllers/Http/admin/FontSettingsController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' | ||
import FontSetting from 'App/Models/FontSetting'; | ||
|
||
export default class FontSettingSettingsController { | ||
|
||
public async store({request, response}: HttpContextContract) { | ||
|
||
let fontSetting = new FontSetting() | ||
fontSetting.fill(request.all()) | ||
|
||
try { | ||
await fontSetting.save() | ||
} catch (e) { | ||
return response.json({ | ||
'success': | ||
false, | ||
'message': | ||
'Font Setting don\'t saved', | ||
'throw message': e.message, | ||
'trace': e.stack.split('\n'), | ||
}, | ||
) | ||
} | ||
return response.json({ | ||
'success': true, | ||
'data': fontSetting | ||
}, | ||
) | ||
} | ||
|
||
public async show({params, response}: HttpContextContract) { | ||
let fontSetting = await FontSetting.find(params.id) | ||
if (!fontSetting) { | ||
return response.json({ | ||
'success': false, | ||
'message': 'Font Setting not found' | ||
}, | ||
) | ||
} | ||
return response.json({ | ||
'success': true, | ||
'data': fontSetting | ||
},) | ||
} | ||
|
||
public async update({params, request, response}: HttpContextContract) { | ||
let fontSetting = await FontSetting.find(params.id) | ||
if (!fontSetting) { | ||
return response.json({ | ||
'success': false, | ||
'message': 'Font Setting not found' | ||
}, | ||
) | ||
} | ||
fontSetting.merge(request.all()) | ||
try { | ||
await fontSetting.save() | ||
} catch (e) { | ||
response.status(500) | ||
return response.json({ | ||
'success': false, | ||
'message': 'Font Setting could not be saved', | ||
'throw message': e.message, | ||
'trace': e.stack.split('\n'), | ||
}, | ||
) | ||
} | ||
return response.json({ | ||
'success': true, | ||
'data': fontSetting.serialize() | ||
}) | ||
} | ||
|
||
public async index({params, response}: HttpContextContract) { | ||
|
||
let fontSettings = FontSetting.query().where('font_guid', params.guid) | ||
|
||
return response.json({ | ||
'success': true, | ||
'data': fontSettings | ||
}) | ||
} | ||
|
||
public async destroy({params, response}: HttpContextContract) { | ||
let fontSetting = await FontSetting.find(params.id) | ||
if (!fontSetting) { | ||
return response.json({ | ||
'success': false, | ||
'message': 'FontSetting not found' | ||
},) | ||
} | ||
try { | ||
await fontSetting.delete() | ||
} catch (e) { | ||
return response.json({ | ||
'success': false, | ||
'throw message': e.message, | ||
'trace': e.stack.split('\n'), | ||
'message': 'Font Setting could not be deleted' | ||
}, | ||
) | ||
} | ||
return response.json({'success': true,}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' | ||
import Font from 'App/Models/Font'; | ||
import validGuid from '../../../../helpers/validGuid'; | ||
import guid from "../../../../helpers/guid"; | ||
|
||
export default class FontsController { | ||
|
||
public async store({request, response}: HttpContextContract) { | ||
|
||
let font = new Font() | ||
font.fill(request.all()) | ||
font.guid = guid() | ||
|
||
try { | ||
await font.save() | ||
} catch (e) { | ||
return response.json({ | ||
'success': | ||
false, | ||
'message': | ||
'Font don\'t saved', | ||
'throw message': e.message, | ||
'trace': e.stack.split('\n'), | ||
}, | ||
) | ||
} | ||
return response.json({ | ||
'success': true, | ||
'data': font | ||
}, | ||
) | ||
} | ||
|
||
public async show({params, response}: HttpContextContract) { | ||
let font | ||
if (validGuid(params.id)) { | ||
font = await font.query().where('guid', params.id).first() | ||
} else { | ||
font = await Font.find(params.id) | ||
} | ||
await font.load('fontSettings') | ||
if (!font) { | ||
return response.json({ | ||
'success': false, | ||
'message': 'Font not found' | ||
}, | ||
) | ||
} | ||
return response.json({ | ||
'success': true, | ||
'data': font | ||
},) | ||
} | ||
|
||
public async update({params, request, response}: HttpContextContract) { | ||
let font = await Font.find(params.id) | ||
if (!font) { | ||
return response.json({ | ||
'success': false, | ||
'message': 'Font not found' | ||
}, | ||
) | ||
} | ||
font.merge(request.all()) | ||
try { | ||
await font.save() | ||
} catch (e) { | ||
console.trace(e); | ||
response.status(500) | ||
return response.json({ | ||
'success': false, | ||
'message': 'Font could not be saved', | ||
'throw message': e.message, | ||
'trace': e.stack.split('\n'), | ||
}, | ||
) | ||
} | ||
return response.json({ | ||
'success': true, | ||
'data': font.serialize() | ||
}) | ||
} | ||
|
||
public async index({request, response}: HttpContextContract) { | ||
|
||
let search = request.qs().s || '' | ||
let categories = request.qs() || '' | ||
let orderColumn = request.qs().order_by || 'font_family' | ||
let orderType: 'asc' | 'desc' = request.qs()?.order ? request.qs().order.toLowerCase() : 'asc' | ||
|
||
let fonts = Font.query().preload('categories') | ||
if (fonts && _.isString(categories)) { | ||
categories = categories.split(',') | ||
fonts.leftJoin('altrp_category_objects', | ||
'altrp_category_objects.object_guid', | ||
'=', | ||
'altrp_fonts.guid') | ||
// @ts-ignore | ||
fonts.whereIn('altrp_category_objects.category_guid', categories) | ||
} | ||
|
||
if (search) { | ||
fonts.where(function (query) { | ||
query.where('altrp_fonts.font_family', 'like', '%' + search + '%') | ||
.orWhere('altrp_fonts.id', 'like', '%' + search + '%') | ||
}) | ||
} | ||
fonts.orderBy(orderColumn, orderType) | ||
const result = await fonts.select('altrp_fonts.*') | ||
|
||
return response.json({ | ||
'success': | ||
true, | ||
'data': | ||
result, | ||
}) | ||
} | ||
|
||
public async destroy({params, response}: HttpContextContract) { | ||
let font | ||
if (validGuid(params.id)) { | ||
font = await Font.query().where('guid', params.id).first() | ||
} else { | ||
font = await Font.find(params.id) | ||
} | ||
if (!font) { | ||
return response.json({ | ||
'success': false, | ||
'message': 'Font not found' | ||
},) | ||
} | ||
try { | ||
await font.delete() | ||
} catch (e) { | ||
return response.json({ | ||
'success': false, | ||
'throw message': e.message, | ||
'trace': e.stack.split('\n'), | ||
'message': 'Font could not be deleted' | ||
}, | ||
) | ||
} | ||
return response.json({'success': true,},) | ||
} | ||
|
||
} |
Oops, something went wrong.