Skip to content

Instantly share code, notes, and snippets.

Avatar

hdd hdd42

  • United States
View GitHub Profile
View service.ts
import { Injectable } from '@angular/core';
declare var APP :{
siteUrl:string,
language:string,
urls:{
base:string
}
}
View routerEvents.ts
this.router.events
.filter(event => event instanceof NavigationEnd)
.subscribe(event => {
console.log("event", event);
//Query params ?name=ali gibi ayni sekilde segmentlerde erisilebilir
this.route
.queryParams
.subscribe(params => {
console.log("Params : ", params)
});
View routerDisidakiComponent.ts
constructor(private router:Router, private route:ActivatedRoute) { }
ngOnInit() {
this.router.events.subscribe(_ev =>{
if(_ev instanceof NavigationEnd){
// eski usul 1 tum url i alip parse edebilirsin,
console.log("Route Id : ", _ev.id, ", Route : ",_ev.url)
//regex veya router service ile yapabilirsin
console.log(this.router.parseUrl(_ev.url))
////NavigationEnd {id: 1, url: "/admin/dashboard/urunler/edit/59123c96d5607e18f47de0b8?stock=true#showTollbar",
View layout.ejs
<!DOCTYPE html>
<html>
<head>
<title><%=typeof title == 'undefined' ? 'New Sails App' : title%></title>
<!-- Viewport mobile tag for sensible mobile support -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!--
View homepage.ejs
<!-- burda ilk yukleme icin ejs ile sunu rendering de yapabilirsin,
sonrasinda kontrolu Javascript/Jquer veya angular vs ye birakabilirsin.
ama transfer edilecek veriler cok buyuk olmadigi icin biz
herseyi web socket uzerinden alip html i istemcide olusturuyoruz. -->
<div id="app" class>
<div class="row mb-2">
<div class="col-md-4">
View app.js
//assets\js\app.js
//javascript i ayri bir dosyaya yazmis olduk
//daha rahat calismak icin bootstrap ve jquery ekledim
getQuestions();
var questions = []
var errorMessage = ""
var questionList = $('#questions')
var loading = $('#loading')
View QuestionController.js
/**
* QuestionController
*
* @description :: Server-side logic for managing questions
* @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers
*/
module.exports = {
current: function (req, res) {
var qId = req.body.id;
View model.js
const mongoose = require('mongoose')
const ObjectId = mongoose.Schema.Types.ObjectId
//vrtual schema, post schema icinde sub field olarak kullanabilirsin.
const CommentSchema = new mongoose.Schema({
comment: {
type: String,
required: [true, "Bu alan Zorunludur!"]
},
user: { type: ObjectId, ref: 'User' },
View gist:7644e5cd61af98ad32fbe6f8853eb4ce
// async / await version
exports.executeSQL = async (sql, parameters) => {
return new Promise((resolve, reject) => {
try {
let conn = new dbSQL.Connection(settings.dbConfig)
await conn.connect();
let req = new dbSQL.Request(conn);
View model.js
/*
ilgili soruyu like yada unlike seklinde oylamak icin rota
router.route("/:id/vote")
.put(ctrl.errorHandler(ctrl.vote))
*/
// soru icin up yada down vote guncelleyen metod
async vote(req, res, next) {
let id = req.params.id;
let upOrDown = req.body.vote;
let userId= req.user._id