I just started taking interest in Sails.JS
and I'm following a educational guide on it by Traversy Media. In this guide everything goes well for me until he generates an API where he accesses it through localhost:1337/articles.
I can't access this file only getting a 404 page, so I went searching on the internet for help. I found out I needed to add /articles to config/routes.js but i haven't figured out what to place in the action part.
At 10:36 in the Traversy Sails.JS tutorial, it shows the part I'm unable to browse to.
Is anyone able to help? Thanks in advance.
ArticlesController.js file is default
My routes.js :
module.exports.routes = {
'GET /': { action: 'view-homepage-or-redirect' },
'GET /welcome': { action: 'dashboard/view-welcome' },
'GET /articles': { action: 'view-Articles' },
'GET /faq': { view: 'pages/faq' },
'GET /legal/terms': { view: 'pages/legal/terms' },
'GET /legal/privacy': { view: 'pages/legal/privacy' },
'GET /contact': { view: 'pages/contact' },
'GET /signup': { action: 'entrance/view-signup' },
'GET /email/confirm': { action: 'entrance/confirm-email' },
'GET /email/confirmed': { view: 'pages/entrance/confirmed-email' },
'GET /login': { action: 'entrance/view-login' },
'GET /password/forgot': { action: 'entrance/view-forgot-password' },
'GET /password/new': { action: 'entrance/view-new-password' },
'GET /account': { action: 'account/view-account-overview' },
'GET /account/password': { action: 'account/view-edit-password' },
'GET /account/profile': { action: 'account/view-edit-profile' },
'/api/v1/account/logout': { action: 'account/logout' },
'PUT /api/v1/account/update-password': { action: 'account/update-password' },
'PUT /api/v1/account/update-profile': { action: 'account/update-profile' },
'PUT /api/v1/account/update-billing-card': { action: 'account/update-billing-card' },
'PUT /api/v1/entrance/login': { action: 'entrance/login' },
'POST /api/v1/entrance/signup': { action: 'entrance/signup' },
'POST /api/v1/entrance/send-password-recovery-email': { action: 'entrance/send-password-recovery-email' },
'POST /api/v1/entrance/update-password-and-login': { action: 'entrance/update-password-and-login' },
'POST /api/v1/deliver-contact-form-message': { action: 'deliver-contact-form-message' },
'/terms': '/legal/terms',
'/logout': '/api/v1/account/logout',
};
Blueprints is also default
If you have in
config/blueprints.js
module.exports.blueprints = {
actions: true,
rest: false,
shortcuts: true,
};
and ArticleController and some action (method) there, eg
module.exports = {
hello: function(req, res) {
return res.json('ok');
}
}
You should be able to see 'ok' by url localhost:1337/Article/hello
Related
I'm trying to upload a file using the code below:
window = Ext.create('Ext.window.Window', {
renderTo: Ext.getBody(),
bodyPadding: '20 10',
title: 'Upload file',
autoDestroy: true,
hidden: true,
modal: true,
layout: {
type: 'hbox',
align: 'middle',
pack: 'center'
},
items: [
uploadForm = new Ext.form.Panel({
items: [
file = new Ext.form.field.File({
xtype: 'filefield',
name: 'fileName',
fieldLabel: 'File',
allowBlank: false,
buttonText: 'Select file...',
})
]
})
],
buttons: [{
text: 'Cancel',
handler: function () {
upload.hide();
}
},
{
text: 'Upload',
handler: function () {
var form = uploadForm.getForm();
if (form.isValid()) {
form.submit({
url: 'upload',
waitMsg: 'Uploading your file...',
scope: this,
success: function (form, action) {
upload.close();
var json = JSON.parse(action.response.responseText);
if (json.success) {
Ext.Msg.alert('Success', json.message);
} else {
Ext.Msg.alert('Error', json.message);
}
},
failure: function (form, action) {
upload.close();
try {
var json = JSON.parse(action.response.responseText);
Ext.create('Ext.window.MessageBox').show({
title: 'Failure',
msg: json.message
});
} catch (err) {
Ext.create('Ext.window.MessageBox')
.alert('Failure', 'Failed to parse response');
}
}
});
}
}
}]
});
The code is working in firefox and opera and I get the response successfully, but in chrome on inspect network activity, the status is canceled and in the console I get the warning: Resource interpreted as Document but transferred with MIME type application/json. Therefore, the submit always returns failure, even though the file is uploaded. Can anyone please suggest how to fix this?
I'm building a Slack API using bolt (on glitch). I'm new to this so and not sure about how to do this particular idea.
Using a slash command I open a modal that lists three radio inputs and has an action button that will use client.views.update to present a multi-line input.
I would like the option chosen to be the initial value of the multi-line code.
// this is required: github.com/slackapi/bolt
app.command("/slashcommand", async ({ ack, payload, context }) => {
// Acknowledge the command request
ack();
try {
const result = app.client.views.open({
token: context.botToken,
// Pass a valid trigger_id within 3 seconds of receiving it
trigger_id: payload.trigger_id,
// View payload
view: {
type: "modal",
callback_id: 'modal_1',
title: {
type: "plain_text",
text: "Initiate Feedback",
emoji: true
}, /*
submit: {
type: "plain_text",
text: "Submit",
emoji: true
}, */
close: {
type: "plain_text",
text: "Cancel",
emoji: true
},
blocks: [
{
type: "context",
elements: [
{
type: "mrkdwn",
text:
"Modal first view"
}
]
},
{
type: "divider"
},
{
type: "section",
block_id: 'radio_block',
text: {
type: "mrkdwn",
text: "Select from one of the following options:"
},
accessory: {
type: "radio_buttons",
action_id: 'radio_input',
initial_option: {
text: {
type: "plain_text",
text: "One"
},
value: "one",
description: {
type: "plain_text",
text: "describe one"
}
},
options: [
{
text: {
type: "plain_text",
text: "One"
},
value: "one",
description: {
type: "plain_text",
text: "describe one"
}
},
{
text: {
type: "plain_text",
text: "Two"
},
value: "two",
description: {
type: "plain_text",
text: "describe two"
}
},
{
text: {
type: "plain_text",
text: "Three"
},
value: "three",
description: {
type: "plain_text",
text: "describe three"
}
}
]
}
},
{
type: "actions",
elements: [
{
type: "button",
text: {
type: "plain_text",
text: "Next",
emoji: true
},
action_id: "next_1"
}
]
}
]
}
});
console.log(result);
} catch (error) {
console.error(error);
}
});
// Listen for a button invocation with action_id `next_1` (assume it's inside of a modal)
app.action("next_1", async ({ ack, body, context }) => {
// VALUE FROM RADIO INPUT
// const val = Radio input value;
// Acknowledge the button request
ack();
try {
const result = app.client.views.update({
token: context.botToken,
// Pass the view_id
view_id: body.view.id,
// View payload with updated blocks
view: {
type: "modal",
// View identifier
callback_id: 'feed_1',
title: {
type: "plain_text",
text: "Share Feedback: message"
},
blocks: [
{
type: "section",
text: {
type: "plain_text",
text: 'You choose '
}
},
{
type: "input",
element: {
type: "plain_text_input",
// HERE IS WHERE THE RADIO OPTION GOES
initial_value: `One `,
multiline: true
},
label: {
type: "plain_text",
text: "Message",
emoji: true
}
}
],
submit: {
type: "plain_text",
text: "Submit"
}
}
});
console.log(result);
} catch (error) {
console.error(error);
}
});
Ok figured this out finally!
1) make sure your radio buttons are not in any input blocks!
2) output your returned payload in your action using body.actions
once you see what your returning it will be easier to target that value.
'''
app.action("next_1", async ({ ack, body, context }) => {
// Result of option selected
const val = JSON.stringify(body['actions'][0]);
// see the values
console.log(val);
// Acknowledge the button request
ack();
});
'''
Further details: https://api.slack.com/reference/interaction-payloads/actions
I'm used Ionic 3 and I'm try to display label for behind the input fields ,but it's not display,why is not showing? please help me to fix it
Thanks
doPrompt() {
let prompt = this.alertCtrl.create({
title: '5 Rooms Available',
message: "",
inputs: [
{
label: "Single Rooms (3)",
name: 'Single Rooms (3)',
placeholder: '$200.00',
},
],
buttons: [
{
text: 'Cancel',
handler: data => {
console.log('Cancel clicked');
}
},
{
text: 'Set',
handler: data => {
console.log('Saved clicked');
}
}
]
});
prompt.present();
}
How to pass selected Value form Popup to normal controller page in ionic framework
`$scope.showprofpopup = function()
{
$scope.data = {}
var myPopup = $ionicPopup.show
({
templateUrl: 'templates/popover.html',
title: 'Please Choose Category',
scope: $scope,
buttons: [ { text : 'Cancel' }, { text: 'Select', type: 'button-dark', onTap: function(e) { return $scope.data; } }, ]
});
myPopup.then(function(res)
{
//$scope.create(res.category);
//$state.go('app.userdetails');
//$scope.contactMessage = { text: res };
if(!res.category)
{
$ionicLoading.show({ template: '<ion-spinner icon="android"></ion-spinner>', animation: 'fade-in', showBackdrop: true, maxWidth: 100,showDelay: 50 });
$scope.showprofpopup();
$timeout(function () { $ionicLoading.hide(); }, 3000);
//$ionicPopup.alert({ title: "Please Choose Category" });
}
else
{
$scope.SelectedProfessional = { text: res.category};
//alert(res.category);
$state.go('app.userdetails');
}
});
};`
I want to send the result re.category to app.userdetails page.kindly anyone help me.
using $stateParams
$state.go('app.userdetails',{'category': res.category});
I am trying reset a form, on click of button.
The button's functionality is defined in file seperate controller file.
But on clicking button reset i get error
"Uncaught TypeError: Object form1orig has no method 'reset' "
Controller
Ext.define('myapp.controller.form1', {
extend: 'Ext.app.Controller',
requires: [
'myapp.view.form1'
],
config: {
refs: {
form1orig: '#pressc',
form1Submit: 'button[action=sub]',
form1Reset: 'button[action=res]'
},
control: {
'form1Reset' : {
tap: 'onForm1Reset'
},
'form1Submit' : {
tap: 'onForm1Submit'
}
}
},
onForm1Reset: function(button){
'form1orig'.reset();
console.log('Tapped reset');
},
onForm1Submit: function(button){
console.log('Tapped submit');
}
});
View
Ext.define('myapp.view.form1', {
extend: 'Ext.form.Panel',
requires: [
'Ext.form.FieldSet',
],
xtype: 'form1Me',
id: 'form1Me',
config: {
items: [
{
xtype: 'fieldset',
id: 'pressc',
instructions: 'Please enter the information above.',
defaults: {
labelWidth: '35%'
},
items: [
{
xtype:'textfield',
name: 'name',
label: 'Name',
id: 'eman',
placeHolder: 'Name'
},
{
xtype: 'textareafield',
name : 'Prescription',
id: 'pres',
label: 'Prescription',
placeHolder: 'Enter your prescription here...'
}
]
},
{
xtype: 'container',
defaults: {
xtype: 'button',
style: 'margin: .5em',
flex : 1
},
layout: {
type: 'hbox'
},
items: [
{
text: 'Submit',
id: 'subMe',
action: 'sub',
scope: this,
hasDisabled: false
//handler: function(btn){
/*var presscForm = Ext.getCmp('presscForm');
presscForm.submit({
url: '../../result.php',
method: 'POST',
success: function() {
alert('Thamk you for using our service');
}
});*/
//}
},
{
text: 'Reset',
id: 'resMe',
action: 'res'
/*handler: function(){
Ext.getCmp('form1Me').reset();
}*/
}
]
}
]
}
});
Help
You should do something like:
var form = Ext.ComponentQuery.query('form1Me');
form.reset();