How to use todo method in tappy

Best Python code snippet using tappy_python

todo_pb.js

Source:todo_pb.js Github

copy

Full Screen

1/**2 * @fileoverview3 * @enhanceable4 * @suppress {messageConventions} JS Compiler reports an error if a variable or5 * field starts with 'MSG_' and isn't a translatable message.6 * @public7 */8// GENERATED CODE -- DO NOT EDIT!9/* eslint-disable */10var jspb = require('google-protobuf');11var goog = jspb;12var global = Function('return this')();13var google_protobuf_Empty_pb = require('google-protobuf/google/protobuf/empty_pb.js');14goog.exportSymbol('proto.todoList.AddTodoRequest', null, global);15goog.exportSymbol('proto.todoList.GetTodoRequest', null, global);16goog.exportSymbol('proto.todoList.Todo', null, global);17goog.exportSymbol('proto.todoList.TodoListResponse', null, global);18/**19 * Generated by JsPbCodeGenerator.20 * @param {Array=} opt_data Optional initial data array, typically from a21 * server response, or constructed directly in Javascript. The array is used22 * in place and becomes part of the constructed object. It is not cloned.23 * If no data is provided, the constructed object will be empty, but still24 * valid.25 * @extends {jspb.Message}26 * @constructor27 */28proto.todoList.TodoListResponse = function(opt_data) {29 jspb.Message.initialize(30 this,31 opt_data,32 0,33 -1,34 proto.todoList.TodoListResponse.repeatedFields_,35 null36 );37};38goog.inherits(proto.todoList.TodoListResponse, jspb.Message);39if (goog.DEBUG && !COMPILED) {40 proto.todoList.TodoListResponse.displayName =41 'proto.todoList.TodoListResponse';42}43/**44 * List of repeated fields within this message type.45 * @private {!Array<number>}46 * @const47 */48proto.todoList.TodoListResponse.repeatedFields_ = [1];49if (jspb.Message.GENERATE_TO_OBJECT) {50 /**51 * Creates an object representation of this proto suitable for use in Soy templates.52 * Field names that are reserved in JavaScript and will be renamed to pb_name.53 * To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.54 * For the list of reserved names please see:55 * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.56 * @param {boolean=} opt_includeInstance Whether to include the JSPB instance57 * for transitional soy proto support: http://goto/soy-param-migration58 * @return {!Object}59 */60 proto.todoList.TodoListResponse.prototype.toObject = function(61 opt_includeInstance62 ) {63 return proto.todoList.TodoListResponse.toObject(opt_includeInstance, this);64 };65 /**66 * Static version of the {@see toObject} method.67 * @param {boolean|undefined} includeInstance Whether to include the JSPB68 * instance for transitional soy proto support:69 * http://goto/soy-param-migration70 * @param {!proto.todoList.TodoListResponse} msg The msg instance to transform.71 * @return {!Object}72 * @suppress {unusedLocalVariables} f is only used for nested messages73 */74 proto.todoList.TodoListResponse.toObject = function(includeInstance, msg) {75 var f,76 obj = {77 todoList: jspb.Message.toObjectList(78 msg.getTodoList(),79 proto.todoList.Todo.toObject,80 includeInstance81 )82 };83 if (includeInstance) {84 obj.$jspbMessageInstance = msg;85 }86 return obj;87 };88}89/**90 * Deserializes binary data (in protobuf wire format).91 * @param {jspb.ByteSource} bytes The bytes to deserialize.92 * @return {!proto.todoList.TodoListResponse}93 */94proto.todoList.TodoListResponse.deserializeBinary = function(bytes) {95 var reader = new jspb.BinaryReader(bytes);96 var msg = new proto.todoList.TodoListResponse();97 return proto.todoList.TodoListResponse.deserializeBinaryFromReader(98 msg,99 reader100 );101};102/**103 * Deserializes binary data (in protobuf wire format) from the104 * given reader into the given message object.105 * @param {!proto.todoList.TodoListResponse} msg The message object to deserialize into.106 * @param {!jspb.BinaryReader} reader The BinaryReader to use.107 * @return {!proto.todoList.TodoListResponse}108 */109proto.todoList.TodoListResponse.deserializeBinaryFromReader = function(110 msg,111 reader112) {113 while (reader.nextField()) {114 if (reader.isEndGroup()) {115 break;116 }117 var field = reader.getFieldNumber();118 switch (field) {119 case 1:120 var value = new proto.todoList.Todo();121 reader.readMessage(122 value,123 proto.todoList.Todo.deserializeBinaryFromReader124 );125 msg.addTodo(value);126 break;127 default:128 reader.skipField();129 break;130 }131 }132 return msg;133};134/**135 * Serializes the message to binary data (in protobuf wire format).136 * @return {!Uint8Array}137 */138proto.todoList.TodoListResponse.prototype.serializeBinary = function() {139 var writer = new jspb.BinaryWriter();140 proto.todoList.TodoListResponse.serializeBinaryToWriter(this, writer);141 return writer.getResultBuffer();142};143/**144 * Serializes the given message to binary data (in protobuf wire145 * format), writing to the given BinaryWriter.146 * @param {!proto.todoList.TodoListResponse} message147 * @param {!jspb.BinaryWriter} writer148 * @suppress {unusedLocalVariables} f is only used for nested messages149 */150proto.todoList.TodoListResponse.serializeBinaryToWriter = function(151 message,152 writer153) {154 var f = undefined;155 f = message.getTodoList();156 if (f.length > 0) {157 writer.writeRepeatedMessage(158 1,159 f,160 proto.todoList.Todo.serializeBinaryToWriter161 );162 }163};164/**165 * repeated Todo todo = 1;166 * @return {!Array<!proto.todoList.Todo>}167 */168proto.todoList.TodoListResponse.prototype.getTodoList = function() {169 return /** @type{!Array<!proto.todoList.Todo>} */ (jspb.Message.getRepeatedWrapperField(170 this,171 proto.todoList.Todo,172 1173 ));174};175/** @param {!Array<!proto.todoList.Todo>} value */176proto.todoList.TodoListResponse.prototype.setTodoList = function(value) {177 jspb.Message.setRepeatedWrapperField(this, 1, value);178};179/**180 * @param {!proto.todoList.Todo=} opt_value181 * @param {number=} opt_index182 * @return {!proto.todoList.Todo}183 */184proto.todoList.TodoListResponse.prototype.addTodo = function(185 opt_value,186 opt_index187) {188 return jspb.Message.addToRepeatedWrapperField(189 this,190 1,191 opt_value,192 proto.todoList.Todo,193 opt_index194 );195};196proto.todoList.TodoListResponse.prototype.clearTodoList = function() {197 this.setTodoList([]);198};199/**200 * Generated by JsPbCodeGenerator.201 * @param {Array=} opt_data Optional initial data array, typically from a202 * server response, or constructed directly in Javascript. The array is used203 * in place and becomes part of the constructed object. It is not cloned.204 * If no data is provided, the constructed object will be empty, but still205 * valid.206 * @extends {jspb.Message}207 * @constructor208 */209proto.todoList.Todo = function(opt_data) {210 jspb.Message.initialize(this, opt_data, 0, -1, null, null);211};212goog.inherits(proto.todoList.Todo, jspb.Message);213if (goog.DEBUG && !COMPILED) {214 proto.todoList.Todo.displayName = 'proto.todoList.Todo';215}216if (jspb.Message.GENERATE_TO_OBJECT) {217 /**218 * Creates an object representation of this proto suitable for use in Soy templates.219 * Field names that are reserved in JavaScript and will be renamed to pb_name.220 * To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.221 * For the list of reserved names please see:222 * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.223 * @param {boolean=} opt_includeInstance Whether to include the JSPB instance224 * for transitional soy proto support: http://goto/soy-param-migration225 * @return {!Object}226 */227 proto.todoList.Todo.prototype.toObject = function(opt_includeInstance) {228 return proto.todoList.Todo.toObject(opt_includeInstance, this);229 };230 /**231 * Static version of the {@see toObject} method.232 * @param {boolean|undefined} includeInstance Whether to include the JSPB233 * instance for transitional soy proto support:234 * http://goto/soy-param-migration235 * @param {!proto.todoList.Todo} msg The msg instance to transform.236 * @return {!Object}237 * @suppress {unusedLocalVariables} f is only used for nested messages238 */239 proto.todoList.Todo.toObject = function(includeInstance, msg) {240 var f,241 obj = {242 id: jspb.Message.getFieldWithDefault(msg, 1, ''),243 title: jspb.Message.getFieldWithDefault(msg, 2, ''),244 detail: jspb.Message.getFieldWithDefault(msg, 3, '')245 };246 if (includeInstance) {247 obj.$jspbMessageInstance = msg;248 }249 return obj;250 };251}252/**253 * Deserializes binary data (in protobuf wire format).254 * @param {jspb.ByteSource} bytes The bytes to deserialize.255 * @return {!proto.todoList.Todo}256 */257proto.todoList.Todo.deserializeBinary = function(bytes) {258 var reader = new jspb.BinaryReader(bytes);259 var msg = new proto.todoList.Todo();260 return proto.todoList.Todo.deserializeBinaryFromReader(msg, reader);261};262/**263 * Deserializes binary data (in protobuf wire format) from the264 * given reader into the given message object.265 * @param {!proto.todoList.Todo} msg The message object to deserialize into.266 * @param {!jspb.BinaryReader} reader The BinaryReader to use.267 * @return {!proto.todoList.Todo}268 */269proto.todoList.Todo.deserializeBinaryFromReader = function(msg, reader) {270 while (reader.nextField()) {271 if (reader.isEndGroup()) {272 break;273 }274 var field = reader.getFieldNumber();275 switch (field) {276 case 1:277 var value = /** @type {string} */ (reader.readString());278 msg.setId(value);279 break;280 case 2:281 var value = /** @type {string} */ (reader.readString());282 msg.setTitle(value);283 break;284 case 3:285 var value = /** @type {string} */ (reader.readString());286 msg.setDetail(value);287 break;288 default:289 reader.skipField();290 break;291 }292 }293 return msg;294};295/**296 * Serializes the message to binary data (in protobuf wire format).297 * @return {!Uint8Array}298 */299proto.todoList.Todo.prototype.serializeBinary = function() {300 var writer = new jspb.BinaryWriter();301 proto.todoList.Todo.serializeBinaryToWriter(this, writer);302 return writer.getResultBuffer();303};304/**305 * Serializes the given message to binary data (in protobuf wire306 * format), writing to the given BinaryWriter.307 * @param {!proto.todoList.Todo} message308 * @param {!jspb.BinaryWriter} writer309 * @suppress {unusedLocalVariables} f is only used for nested messages310 */311proto.todoList.Todo.serializeBinaryToWriter = function(message, writer) {312 var f = undefined;313 f = message.getId();314 if (f.length > 0) {315 writer.writeString(1, f);316 }317 f = message.getTitle();318 if (f.length > 0) {319 writer.writeString(2, f);320 }321 f = message.getDetail();322 if (f.length > 0) {323 writer.writeString(3, f);324 }325};326/**327 * optional string id = 1;328 * @return {string}329 */330proto.todoList.Todo.prototype.getId = function() {331 return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ''));332};333/** @param {string} value */334proto.todoList.Todo.prototype.setId = function(value) {335 jspb.Message.setProto3StringField(this, 1, value);336};337/**338 * optional string title = 2;339 * @return {string}340 */341proto.todoList.Todo.prototype.getTitle = function() {342 return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, ''));343};344/** @param {string} value */345proto.todoList.Todo.prototype.setTitle = function(value) {346 jspb.Message.setProto3StringField(this, 2, value);347};348/**349 * optional string detail = 3;350 * @return {string}351 */352proto.todoList.Todo.prototype.getDetail = function() {353 return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, ''));354};355/** @param {string} value */356proto.todoList.Todo.prototype.setDetail = function(value) {357 jspb.Message.setProto3StringField(this, 3, value);358};359/**360 * Generated by JsPbCodeGenerator.361 * @param {Array=} opt_data Optional initial data array, typically from a362 * server response, or constructed directly in Javascript. The array is used363 * in place and becomes part of the constructed object. It is not cloned.364 * If no data is provided, the constructed object will be empty, but still365 * valid.366 * @extends {jspb.Message}367 * @constructor368 */369proto.todoList.GetTodoRequest = function(opt_data) {370 jspb.Message.initialize(this, opt_data, 0, -1, null, null);371};372goog.inherits(proto.todoList.GetTodoRequest, jspb.Message);373if (goog.DEBUG && !COMPILED) {374 proto.todoList.GetTodoRequest.displayName = 'proto.todoList.GetTodoRequest';375}376if (jspb.Message.GENERATE_TO_OBJECT) {377 /**378 * Creates an object representation of this proto suitable for use in Soy templates.379 * Field names that are reserved in JavaScript and will be renamed to pb_name.380 * To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.381 * For the list of reserved names please see:382 * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.383 * @param {boolean=} opt_includeInstance Whether to include the JSPB instance384 * for transitional soy proto support: http://goto/soy-param-migration385 * @return {!Object}386 */387 proto.todoList.GetTodoRequest.prototype.toObject = function(388 opt_includeInstance389 ) {390 return proto.todoList.GetTodoRequest.toObject(opt_includeInstance, this);391 };392 /**393 * Static version of the {@see toObject} method.394 * @param {boolean|undefined} includeInstance Whether to include the JSPB395 * instance for transitional soy proto support:396 * http://goto/soy-param-migration397 * @param {!proto.todoList.GetTodoRequest} msg The msg instance to transform.398 * @return {!Object}399 * @suppress {unusedLocalVariables} f is only used for nested messages400 */401 proto.todoList.GetTodoRequest.toObject = function(includeInstance, msg) {402 var f,403 obj = {404 id: jspb.Message.getFieldWithDefault(msg, 1, '')405 };406 if (includeInstance) {407 obj.$jspbMessageInstance = msg;408 }409 return obj;410 };411}412/**413 * Deserializes binary data (in protobuf wire format).414 * @param {jspb.ByteSource} bytes The bytes to deserialize.415 * @return {!proto.todoList.GetTodoRequest}416 */417proto.todoList.GetTodoRequest.deserializeBinary = function(bytes) {418 var reader = new jspb.BinaryReader(bytes);419 var msg = new proto.todoList.GetTodoRequest();420 return proto.todoList.GetTodoRequest.deserializeBinaryFromReader(msg, reader);421};422/**423 * Deserializes binary data (in protobuf wire format) from the424 * given reader into the given message object.425 * @param {!proto.todoList.GetTodoRequest} msg The message object to deserialize into.426 * @param {!jspb.BinaryReader} reader The BinaryReader to use.427 * @return {!proto.todoList.GetTodoRequest}428 */429proto.todoList.GetTodoRequest.deserializeBinaryFromReader = function(430 msg,431 reader432) {433 while (reader.nextField()) {434 if (reader.isEndGroup()) {435 break;436 }437 var field = reader.getFieldNumber();438 switch (field) {439 case 1:440 var value = /** @type {string} */ (reader.readString());441 msg.setId(value);442 break;443 default:444 reader.skipField();445 break;446 }447 }448 return msg;449};450/**451 * Serializes the message to binary data (in protobuf wire format).452 * @return {!Uint8Array}453 */454proto.todoList.GetTodoRequest.prototype.serializeBinary = function() {455 var writer = new jspb.BinaryWriter();456 proto.todoList.GetTodoRequest.serializeBinaryToWriter(this, writer);457 return writer.getResultBuffer();458};459/**460 * Serializes the given message to binary data (in protobuf wire461 * format), writing to the given BinaryWriter.462 * @param {!proto.todoList.GetTodoRequest} message463 * @param {!jspb.BinaryWriter} writer464 * @suppress {unusedLocalVariables} f is only used for nested messages465 */466proto.todoList.GetTodoRequest.serializeBinaryToWriter = function(467 message,468 writer469) {470 var f = undefined;471 f = message.getId();472 if (f.length > 0) {473 writer.writeString(1, f);474 }475};476/**477 * optional string id = 1;478 * @return {string}479 */480proto.todoList.GetTodoRequest.prototype.getId = function() {481 return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ''));482};483/** @param {string} value */484proto.todoList.GetTodoRequest.prototype.setId = function(value) {485 jspb.Message.setProto3StringField(this, 1, value);486};487/**488 * Generated by JsPbCodeGenerator.489 * @param {Array=} opt_data Optional initial data array, typically from a490 * server response, or constructed directly in Javascript. The array is used491 * in place and becomes part of the constructed object. It is not cloned.492 * If no data is provided, the constructed object will be empty, but still493 * valid.494 * @extends {jspb.Message}495 * @constructor496 */497proto.todoList.AddTodoRequest = function(opt_data) {498 jspb.Message.initialize(this, opt_data, 0, -1, null, null);499};500goog.inherits(proto.todoList.AddTodoRequest, jspb.Message);501if (goog.DEBUG && !COMPILED) {502 proto.todoList.AddTodoRequest.displayName = 'proto.todoList.AddTodoRequest';503}504if (jspb.Message.GENERATE_TO_OBJECT) {505 /**506 * Creates an object representation of this proto suitable for use in Soy templates.507 * Field names that are reserved in JavaScript and will be renamed to pb_name.508 * To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.509 * For the list of reserved names please see:510 * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.511 * @param {boolean=} opt_includeInstance Whether to include the JSPB instance512 * for transitional soy proto support: http://goto/soy-param-migration513 * @return {!Object}514 */515 proto.todoList.AddTodoRequest.prototype.toObject = function(516 opt_includeInstance517 ) {518 return proto.todoList.AddTodoRequest.toObject(opt_includeInstance, this);519 };520 /**521 * Static version of the {@see toObject} method.522 * @param {boolean|undefined} includeInstance Whether to include the JSPB523 * instance for transitional soy proto support:524 * http://goto/soy-param-migration525 * @param {!proto.todoList.AddTodoRequest} msg The msg instance to transform.526 * @return {!Object}527 * @suppress {unusedLocalVariables} f is only used for nested messages528 */529 proto.todoList.AddTodoRequest.toObject = function(includeInstance, msg) {530 var f,531 obj = {532 title: jspb.Message.getFieldWithDefault(msg, 1, ''),533 detail: jspb.Message.getFieldWithDefault(msg, 2, '')534 };535 if (includeInstance) {536 obj.$jspbMessageInstance = msg;537 }538 return obj;539 };540}541/**542 * Deserializes binary data (in protobuf wire format).543 * @param {jspb.ByteSource} bytes The bytes to deserialize.544 * @return {!proto.todoList.AddTodoRequest}545 */546proto.todoList.AddTodoRequest.deserializeBinary = function(bytes) {547 var reader = new jspb.BinaryReader(bytes);548 var msg = new proto.todoList.AddTodoRequest();549 return proto.todoList.AddTodoRequest.deserializeBinaryFromReader(msg, reader);550};551/**552 * Deserializes binary data (in protobuf wire format) from the553 * given reader into the given message object.554 * @param {!proto.todoList.AddTodoRequest} msg The message object to deserialize into.555 * @param {!jspb.BinaryReader} reader The BinaryReader to use.556 * @return {!proto.todoList.AddTodoRequest}557 */558proto.todoList.AddTodoRequest.deserializeBinaryFromReader = function(559 msg,560 reader561) {562 while (reader.nextField()) {563 if (reader.isEndGroup()) {564 break;565 }566 var field = reader.getFieldNumber();567 switch (field) {568 case 1:569 var value = /** @type {string} */ (reader.readString());570 msg.setTitle(value);571 break;572 case 2:573 var value = /** @type {string} */ (reader.readString());574 msg.setDetail(value);575 break;576 default:577 reader.skipField();578 break;579 }580 }581 return msg;582};583/**584 * Serializes the message to binary data (in protobuf wire format).585 * @return {!Uint8Array}586 */587proto.todoList.AddTodoRequest.prototype.serializeBinary = function() {588 var writer = new jspb.BinaryWriter();589 proto.todoList.AddTodoRequest.serializeBinaryToWriter(this, writer);590 return writer.getResultBuffer();591};592/**593 * Serializes the given message to binary data (in protobuf wire594 * format), writing to the given BinaryWriter.595 * @param {!proto.todoList.AddTodoRequest} message596 * @param {!jspb.BinaryWriter} writer597 * @suppress {unusedLocalVariables} f is only used for nested messages598 */599proto.todoList.AddTodoRequest.serializeBinaryToWriter = function(600 message,601 writer602) {603 var f = undefined;604 f = message.getTitle();605 if (f.length > 0) {606 writer.writeString(1, f);607 }608 f = message.getDetail();609 if (f.length > 0) {610 writer.writeString(2, f);611 }612};613/**614 * optional string title = 1;615 * @return {string}616 */617proto.todoList.AddTodoRequest.prototype.getTitle = function() {618 return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ''));619};620/** @param {string} value */621proto.todoList.AddTodoRequest.prototype.setTitle = function(value) {622 jspb.Message.setProto3StringField(this, 1, value);623};624/**625 * optional string detail = 2;626 * @return {string}627 */628proto.todoList.AddTodoRequest.prototype.getDetail = function() {629 return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, ''));630};631/** @param {string} value */632proto.todoList.AddTodoRequest.prototype.setDetail = function(value) {633 jspb.Message.setProto3StringField(this, 2, value);634};...

Full Screen

Full Screen

todos.js

Source:todos.js Github

copy

Full Screen

1const express = require("express");2const morgan = require("morgan");3const flash = require("express-flash");4const session = require("express-session");5const { body, validationResult } = require("express-validator");6const TodoList = require("./lib/todolist");7const { sortTodoLists, sortTodos } = require("./lib/sort");8const store = require("connect-loki");9const app = express();10const host = "localhost";11const port = 3000;12const LokiStore = store(session);13const Todo = require("./lib/todo");14const removeTodoList = (todoListId, todoLists) => {15 let todoListIdx = todoLists.findIndex(todoList => todoList.id === todoListId);16 todoLists.splice(todoListIdx, 1);17}18app.set("views", "./views");19app.set("view engine", "pug");20app.use(morgan("common"));21app.use(express.static("public"));22app.use(express.urlencoded({ extended: false }));23app.use(session({24 cookie: {25 httpOnly: true,26 maxAge: 31 * 24 * 60 * 60 * 1000, // 31 days in millseconds27 path: "/",28 secure: false,29 },30 name: "launch-school-todos-session-id",31 resave: false,32 saveUninitialized: true,33 secret: "this is not very secure",34 store: new LokiStore({}),35}));36app.use(flash());37// Set up persistent session data38app.use((req, res, next) => {39 let todoLists = [];40 if ("todoLists" in req.session) {41 req.session.todoLists.forEach(todoList => {42 todoLists.push(TodoList.makeTodoList(todoList));43 });44 }45 req.session.todoLists = todoLists;46 next();47});48app.use((req, res, next) => {49 res.locals.flash = req.session.flash;50 delete req.session.flash;51 next();52});53app.use((err, req, res, _next) => {54 console.log(err);55 res.status(404).send(err.message);56});57const loadTodoList = (todoListId, todoLists) => {58 return todoLists.find(todoList => todoList.id === todoListId);59};60// I added this61const loadTodo = (todoList, todoId, todoLists) => {62 return todoList.todos.find(todo => todo.id === Number(todoId));63};64app.get("/", (req, res) => {65 res.redirect("/lists");66});67app.get("/lists/new", (req, res) => {68 res.render("new-list");69});70app.post("/lists",71 [72 body("todoListTitle")73 .trim()74 .isLength({ min: 1 })75 .withMessage("The list title is required.")76 .isLength({ max: 100 })77 .withMessage("List title must be between 1 and 100 characters.")78 .custom((title, { req }) => {79 let todoLists = req.session.todoLists;80 let duplicate = todoLists.find(list => list.title === title);81 return duplicate === undefined;82 })83 .withMessage("List title must be unique."),84 ],85 (req, res) => {86 let errors = validationResult(req);87 if (!errors.isEmpty()) {88 errors.array().forEach(message => req.flash("error", message.msg));89 res.render("new-list", {90 flash: req.flash(),91 todoListTitle: req.body.todoListTitle,92 });93 } else {94 let todoLists = req.session.todoLists;95 todoLists.push(new TodoList(req.body.todoListTitle));96 req.flash("success", "The todo list has been created.");97 res.redirect("/lists");98 }99 }100);101app.get("/lists", (req, res) => {102 res.render("lists", {103 todoLists: sortTodoLists(req.session.todoLists),104 });105});106app.get("/lists/:todoListId", (req, res, next) => {107 let todoListId = req.params.todoListId;108 let todoList = loadTodoList(+todoListId, req.session.todoLists);109 if (todoList === undefined) {110 next(new Error("Not found."));111 } else {112 res.render("list", {113 todoList: todoList,114 todos: sortTodos(todoList),115 });116 }117});118app.get("/lists/:todoListId/edit", (req, res, next) => {119 let todoListId = req.params.todoListId;120 let todoList = loadTodoList(+todoListId, req.session.todoLists);121 if (!todoList) {122 next(new Error("Not found."));123 } else {124 res.render("edit-list", {todoList: todoList});125 }126});127app.post("/lists/:todoListId/todos/:todoId/toggle", (req, res) => {128 let todoLists = req.session.todoLists;129 let todoListId = req.params.todoListId;130 let todoList = loadTodoList(+todoListId, todoLists);131 let todoId = req.params.todoId;132 let todo = loadTodo(todoList, todoId, todoLists);133 if (!todo || !todoList) {134 next(new Error("Not found."));135 } else { 136 todo.isDone() ? todo.markUndone() : todo.markDone();137 req.flash("success", `Your task has been marked ${todo.isDone() ? 'done' : 'undone'}.`);138 res.redirect(`/lists/${todoListId}/`);139 }140});141app.post("/lists/:todoListId/complete_all", (req, res) => {142 let todoListId = req.params.todoListId;143 let todoList = loadTodoList(+todoListId, req.session.todoLists);144 if (!todoList) {145 next(new Error('Not found.'));146 } else {147 todoList.markAllDone();148 req.flash("success", "All tasks have been marked done.");149 res.redirect(`/lists/${todoListId}`);150 }151})152app.post("/lists/:todoListId/todos",153 [154 body("todoTitle")155 .trim()156 .isLength({ min: 1 })157 .withMessage("Todo must be between 1 and 100 characters.")158 .isLength({ max: 100 })159 .withMessage("Todo must be between 1 and 100 characters.")160 ],161 (req, res, next) => {162 let todoListId = req.params.todoListId;163 let todoList = loadTodoList(+todoListId, req.session.todoLists);164 let errors = validationResult(req);165 if (!todoList) {166 next(new Error('Not found.')); 167 } else if (!errors.isEmpty()) {168 errors.array().forEach(message => req.flash("error", message.msg));169 res.render("list", {170 flash: req.flash(),171 todoList: todoList,172 todos: sortTodos(todoList),173 todoTitle: req.body.todoTitle,174 });175 } else {176 let todo = new Todo(req.body.todoTitle);177 todoList.add(todo);178 req.flash("sucess", "The todo has been created.");179 res.redirect(`/lists/${todoListId}`);180 }181 });182app.post("/lists/:todoListId/destroy", (req, res, next) => {183 let todoListId = req.params.todoListId;184 let todoList = loadTodoList(+todoListId, req.session.todoLists);185 186 if (!todoList) {187 next(new Error('Not found.'));188 } else {189 removeTodoList(todoListId, req.session.todoLists);190 req.flash("sucess", "The todo list has been deleted.");191 res.redirect("/lists");192 }193});194// stopped here195app.post("/lists/:todoListId/edit",196 [197 body("todoListTitle")198 .trim()199 .isLength({ min: 1 })200 .withMessage("The new title must be between 1 and 100 characters.")201 .isLength({ max: 100 })202 .withMessage("List title must be between 1 and 100 characters.")203 .custom((title, { req }) => {204 let todoLists = req.session.todoLists;205 let duplicate = todoLists.find(list => list.title === title);206 return duplicate === undefined;207 })208 .withMessage("List title must be unique."),209 ],210 (req, res, next) => {211 let todoListId = req.params.todoListId;212 let todoList = loadTodoList(+todoListId, req.session.todoLists);213 let errors = validationResult(req);214 if (!todoList) {215 next(new Error('Not found.'));216 } 217 218 else if (!errors.isEmpty()) {219 errors.array().forEach(message => req.flash("error", message.msg));220 res.render("edit-list", {221 flash: req.flash(),222 todoListTitle: req.body.todoListTitle,223 todoList: todoList224 });225 } else {226 todoList.setTitle(req.body.todoListTitle);227 req.flash("success", "The todo list title has been updated.");228 res.redirect(`/lists/${todoListId}`);229 }230 });231app.listen(port, host, () => {232 console.log(`Todos is listening on port ${port} of ${host}!`);...

Full Screen

Full Screen

todolistresponse.js

Source:todolistresponse.js Github

copy

Full Screen

1/**2 * @fileoverview3 * @enhanceable4 * @suppress {messageConventions} JS Compiler reports an error if a variable or5 * field starts with 'MSG_' and isn't a translatable message.6 * @public7 */8// GENERATED CODE -- DO NOT EDIT!9goog.provide('proto.todoList.TodoListResponse');10goog.require('jspb.BinaryReader');11goog.require('jspb.BinaryWriter');12goog.require('jspb.Message');13goog.require('proto.todoList.Todo');14/**15 * Generated by JsPbCodeGenerator.16 * @param {Array=} opt_data Optional initial data array, typically from a17 * server response, or constructed directly in Javascript. The array is used18 * in place and becomes part of the constructed object. It is not cloned.19 * If no data is provided, the constructed object will be empty, but still20 * valid.21 * @extends {jspb.Message}22 * @constructor23 */24proto.todoList.TodoListResponse = function(opt_data) {25 jspb.Message.initialize(this, opt_data, 0, -1, proto.todoList.TodoListResponse.repeatedFields_, null);26};27goog.inherits(proto.todoList.TodoListResponse, jspb.Message);28if (goog.DEBUG && !COMPILED) {29 proto.todoList.TodoListResponse.displayName = 'proto.todoList.TodoListResponse';30}31/**32 * List of repeated fields within this message type.33 * @private {!Array<number>}34 * @const35 */36proto.todoList.TodoListResponse.repeatedFields_ = [1];37if (jspb.Message.GENERATE_TO_OBJECT) {38/**39 * Creates an object representation of this proto suitable for use in Soy templates.40 * Field names that are reserved in JavaScript and will be renamed to pb_name.41 * To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.42 * For the list of reserved names please see:43 * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.44 * @param {boolean=} opt_includeInstance Whether to include the JSPB instance45 * for transitional soy proto support: http://goto/soy-param-migration46 * @return {!Object}47 */48proto.todoList.TodoListResponse.prototype.toObject = function(opt_includeInstance) {49 return proto.todoList.TodoListResponse.toObject(opt_includeInstance, this);50};51/**52 * Static version of the {@see toObject} method.53 * @param {boolean|undefined} includeInstance Whether to include the JSPB54 * instance for transitional soy proto support:55 * http://goto/soy-param-migration56 * @param {!proto.todoList.TodoListResponse} msg The msg instance to transform.57 * @return {!Object}58 * @suppress {unusedLocalVariables} f is only used for nested messages59 */60proto.todoList.TodoListResponse.toObject = function(includeInstance, msg) {61 var f, obj = {62 todoList: jspb.Message.toObjectList(msg.getTodoList(),63 proto.todoList.Todo.toObject, includeInstance)64 };65 if (includeInstance) {66 obj.$jspbMessageInstance = msg;67 }68 return obj;69};70}71/**72 * Deserializes binary data (in protobuf wire format).73 * @param {jspb.ByteSource} bytes The bytes to deserialize.74 * @return {!proto.todoList.TodoListResponse}75 */76proto.todoList.TodoListResponse.deserializeBinary = function(bytes) {77 var reader = new jspb.BinaryReader(bytes);78 var msg = new proto.todoList.TodoListResponse;79 return proto.todoList.TodoListResponse.deserializeBinaryFromReader(msg, reader);80};81/**82 * Deserializes binary data (in protobuf wire format) from the83 * given reader into the given message object.84 * @param {!proto.todoList.TodoListResponse} msg The message object to deserialize into.85 * @param {!jspb.BinaryReader} reader The BinaryReader to use.86 * @return {!proto.todoList.TodoListResponse}87 */88proto.todoList.TodoListResponse.deserializeBinaryFromReader = function(msg, reader) {89 while (reader.nextField()) {90 if (reader.isEndGroup()) {91 break;92 }93 var field = reader.getFieldNumber();94 switch (field) {95 case 1:96 var value = new proto.todoList.Todo;97 reader.readMessage(value,proto.todoList.Todo.deserializeBinaryFromReader);98 msg.addTodo(value);99 break;100 default:101 reader.skipField();102 break;103 }104 }105 return msg;106};107/**108 * Serializes the message to binary data (in protobuf wire format).109 * @return {!Uint8Array}110 */111proto.todoList.TodoListResponse.prototype.serializeBinary = function() {112 var writer = new jspb.BinaryWriter();113 proto.todoList.TodoListResponse.serializeBinaryToWriter(this, writer);114 return writer.getResultBuffer();115};116/**117 * Serializes the given message to binary data (in protobuf wire118 * format), writing to the given BinaryWriter.119 * @param {!proto.todoList.TodoListResponse} message120 * @param {!jspb.BinaryWriter} writer121 * @suppress {unusedLocalVariables} f is only used for nested messages122 */123proto.todoList.TodoListResponse.serializeBinaryToWriter = function(message, writer) {124 var f = undefined;125 f = message.getTodoList();126 if (f.length > 0) {127 writer.writeRepeatedMessage(128 1,129 f,130 proto.todoList.Todo.serializeBinaryToWriter131 );132 }133};134/**135 * repeated Todo todo = 1;136 * @return {!Array<!proto.todoList.Todo>}137 */138proto.todoList.TodoListResponse.prototype.getTodoList = function() {139 return /** @type{!Array<!proto.todoList.Todo>} */ (140 jspb.Message.getRepeatedWrapperField(this, proto.todoList.Todo, 1));141};142/** @param {!Array<!proto.todoList.Todo>} value */143proto.todoList.TodoListResponse.prototype.setTodoList = function(value) {144 jspb.Message.setRepeatedWrapperField(this, 1, value);145};146/**147 * @param {!proto.todoList.Todo=} opt_value148 * @param {number=} opt_index149 * @return {!proto.todoList.Todo}150 */151proto.todoList.TodoListResponse.prototype.addTodo = function(opt_value, opt_index) {152 return jspb.Message.addToRepeatedWrapperField(this, 1, opt_value, proto.todoList.Todo, opt_index);153};154proto.todoList.TodoListResponse.prototype.clearTodoList = function() {155 this.setTodoList([]);...

Full Screen

Full Screen

todomvc.js

Source:todomvc.js Github

copy

Full Screen

1module.exports = {2 'todomvc': function (browser) {3 browser4 .url('http://localhost:8080/examples/todomvc/#test')5 .waitForElementVisible('.todoapp', 1000)6 .assert.notVisible('.main')7 .assert.notVisible('.footer')8 .assert.count('.filters .selected', 1)9 .assert.evaluate(function () {10 return document.querySelector('.filters .selected').textContent === 'All'11 })12 createNewItem('test')13 .assert.count('.todo', 1)14 .assert.notVisible('.todo .edit')15 .assert.containsText('.todo label', 'test')16 .assert.containsText('.todo-count strong', '1')17 .assert.checked('.todo .toggle', false)18 .assert.visible('.main')19 .assert.visible('.footer')20 .assert.notVisible('.clear-completed')21 .assert.value('.new-todo', '')22 createNewItem('test2')23 .assert.count('.todo', 2)24 .assert.containsText('.todo:nth-child(2) label', 'test2')25 .assert.containsText('.todo-count strong', '2')26 // toggle27 browser28 .click('.todo .toggle')29 .assert.count('.todo.completed', 1)30 .assert.cssClassPresent('.todo:nth-child(1)', 'completed')31 .assert.containsText('.todo-count strong', '1')32 .assert.visible('.clear-completed')33 createNewItem('test3')34 .assert.count('.todo', 3)35 .assert.containsText('.todo:nth-child(3) label', 'test3')36 .assert.containsText('.todo-count strong', '2')37 createNewItem('test4')38 createNewItem('test5')39 .assert.count('.todo', 5)40 .assert.containsText('.todo-count strong', '4')41 // toggle more42 browser43 .click('.todo:nth-child(4) .toggle')44 .click('.todo:nth-child(5) .toggle')45 .assert.count('.todo.completed', 3)46 .assert.containsText('.todo-count strong', '2')47 // remove48 removeItemAt(1)49 .assert.count('.todo', 4)50 .assert.count('.todo.completed', 2)51 .assert.containsText('.todo-count strong', '2')52 removeItemAt(2)53 .assert.count('.todo', 3)54 .assert.count('.todo.completed', 2)55 .assert.containsText('.todo-count strong', '1')56 // remove all57 browser58 .click('.clear-completed')59 .assert.count('.todo', 1)60 .assert.containsText('.todo label', 'test2')61 .assert.count('.todo.completed', 0)62 .assert.containsText('.todo-count strong', '1')63 .assert.notVisible('.clear-completed')64 // prepare to test filters65 createNewItem('test')66 createNewItem('test')67 .click('.todo:nth-child(2) .toggle')68 .click('.todo:nth-child(3) .toggle')69 // active filter70 browser71 .click('.filters li:nth-child(2) a')72 .assert.count('.todo', 1)73 .assert.count('.todo.completed', 0)74 // add item with filter active75 createNewItem('test')76 .assert.count('.todo', 2)77 // complted filter78 browser.click('.filters li:nth-child(3) a')79 .assert.count('.todo', 2)80 .assert.count('.todo.completed', 2)81 // filter on page load82 browser.url('http://localhost:8080/examples/todomvc/#active')83 .assert.count('.todo', 2)84 .assert.count('.todo.completed', 0)85 .assert.containsText('.todo-count strong', '2')86 // completed on page load87 browser.url('http://localhost:8080/examples/todomvc/#completed')88 .assert.count('.todo', 2)89 .assert.count('.todo.completed', 2)90 .assert.containsText('.todo-count strong', '2')91 // toggling with filter active92 browser93 .click('.todo .toggle')94 .assert.count('.todo', 1)95 .click('.filters li:nth-child(2) a')96 .assert.count('.todo', 3)97 .click('.todo .toggle')98 .assert.count('.todo', 2)99 // editing triggered by blur100 browser101 .click('.filters li:nth-child(1) a')102 .dblClick('.todo:nth-child(1) label')103 .assert.count('.todo.editing', 1)104 .assert.focused('.todo:nth-child(1) .edit')105 .clearValue('.todo:nth-child(1) .edit')106 .setValue('.todo:nth-child(1) .edit', 'edited!')107 .click('footer') // blur108 .assert.count('.todo.editing', 0)109 .assert.containsText('.todo:nth-child(1) label', 'edited!')110 // editing triggered by enter111 browser112 .dblClick('.todo label')113 .enterValue('.todo:nth-child(1) .edit', 'edited again!')114 .assert.count('.todo.editing', 0)115 .assert.containsText('.todo:nth-child(1) label', 'edited again!')116 // cancel117 browser118 .dblClick('.todo label')119 .clearValue('.todo:nth-child(1) .edit')120 .setValue('.todo:nth-child(1) .edit', 'edited!')121 .trigger('.todo:nth-child(1) .edit', 'keyup', 27)122 .assert.count('.todo.editing', 0)123 .assert.containsText('.todo:nth-child(1) label', 'edited again!')124 // empty value should remove125 browser126 .dblClick('.todo label')127 .enterValue('.todo:nth-child(1) .edit', ' ')128 .assert.count('.todo', 3)129 // toggle all130 browser131 .click('.toggle-all')132 .assert.count('.todo.completed', 3)133 .click('.toggle-all')134 .assert.count('.todo:not(.completed)', 3)135 .end()136 function createNewItem (text) {137 return browser.enterValue('.new-todo', text)138 }139 function removeItemAt (n) {140 return browser141 .moveToElement('.todo:nth-child(' + n + ')', 10, 10)142 .click('.todo:nth-child(' + n + ') .destroy')143 }144 }...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tappy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful