讲解:COMP3322A、NodeJS/Express、Java、JavaC/C++|Matlab

COMP3322A Modern Technologies on World Wide WebAssignment 1: A Simple Webmail System (20%)[Learning Outcomes 1, 2]Due by: 23:59, Wednesday November 6, 2019Total mark is 100.OverviewIn this assignment, you are going to develop a simple web-based email system usingNodeJS/Express.js, MongoDB, JavaScript, AJAX, HTML and CSS. The webmail systemimplements a few simplified functionalities, including displaying emails in your mailboxes,moving emails from one mailbox to another and compose new messages. The web-basedemail system is to be implemented by the following code in an Express app:app.js./public/webmail.html./public/javascripts/script.js./public/stylesheets/style.cssand accessed at http://127.0.0.1:8081/webmail.html.Preparations1. Following steps in setup_nodejs_runtime_and_examples_1.docx, install the Node.jsenvironment and the Express framework, and create an Express project named WebMail.2. Following steps in Lab 4, install MongoDB, run MongoDB server, and create a database“assignment1” in the database server.Insert a number of email documents into an emailList collection in the database in theformat as follows:Each email document in the emailList collection contains the following key-value pairs:x _id: The unique ID of the document, which you do not need to include wheninserting a document, and MongoDB server will add automatically into eachinserted document. You can find out such a _id using db.emailList.find().db.emailList.insert({sender:amy@cs.hku.hk, recipient:john@cs.hku.hk,title:Meeting today, time:20:32:01 Fri Oct 11 2019, content:Shall we meet at thelibrary at 5pm?, mailbox:Inbox})n-osnosssttnnnsensons-ensonnnsonn-s-tsensonnsnszgesoonesoennsnnsnsnososen-tnstnnnsn.gs DB 入 dataoniii.恐x sender – The email address of the sender.x recipient – The email address of the recipient.x title – The title of the email.x time – The time when the email was sent.x content – The content of the email.xmailbox – The mailbox which the email belongs to, among Inbox, Important, Sentand Trash.Please prepare at least 3 pages of emails in each mailbox in the emailList collection. That is tosay, if you set the number of emails to display on each page in the email division to be 3,then you should prepare at least 9 email documents for each mailbox in the collection.Task 1 (15 marks) Create basic webmail.html and app.js1. Client sideCreate webmail.html which renders the layout shown in the following figure, i.e., the pagehas four main divisions: heading, function buttons, mailbox list and email list. You can designany heading, showing the name of your webmail system. In the function division, thereshould be four buttons: “Compose”, “Move to …”, “”. You can implement thebuttons using any elements you like, as long as they are clickable and upon clicking, thecorresponding functionality can be achieved. In the mailbox division, include four links:“Inbox”, “Important”, “Sent” “Trash”. In the email division, the email entries will bedynamically loaded from the server side, to be implemented in Task 2.2. Server sideIn app.js, add necessary code for loading the MongoDB database you have created, creatingan instance of the database, and passing the database instance for usage of all middlewares.Also load any other modules and add other middlewares which you may need to implementthis application.Add the middleware for serving static file in the “./public” directory.We will let the server run on the port 8081 and launch the Express app using command“node app.js”.Task 2 (25 marks) Display the email listWhen webmail.html is first loaded, it should be showing the “Inbox” view (Fig. 1): The“Inbox” link in the mailbox division should be in a different color (e.g., “color 1”) from thecolor of the other mailbox links (e.g., “color 2”); when the “Move to …” button is clicked, adrop-down list should be shown, containing three entries: “Important”, “Sent”, and “Trash”.A fixed number of emails in the inbox are listed in the email division, following the formatshown in Fig. 1 (checkbox, sender, title, time). You can specify the number of emails fordisplay on a page.After you click “Important” in the mailbox division, the web page should be showing the“Important” mailbox view: The “Important” link turns into color 1 and the other three linksare in color 2; when the “Move to …” button is clicked, the drop-down list contains threeentries: “Inbox”, “Sent”, and “Trash”. A fixed number of emails in the “Important” mailboxwill be listed in the email division according to the format in Fig. 1 and the number youspecified.When you click “Trash” in the mailbox division, the web page should be showing the “Trash”mailbox view: The “Trash” link turns into color 1 and the other three links are in color 2;when the “Move to …” button is clicked, the drop-down list contains three entries: “Inbox”,“Sent”, and “Important”. A fixed number of emails in the “Trash” mailbox will be listed in theemail division according to the format in Fig. 1 and the number you specified.When you click “Sent” in the mailbox division, the web page should be showing the “Sent”mailbox view (Fig. 2): The “Sent” link turns into color 1 and the other three links are in color2; when the “Move to …” button is clicked, the drop-down list contains three entries: “Inbox”,“Important” and “Trash”. A fixed number of emails in the “Sent” mailbox will be listed in theemail division according to the format in Fig. 2 (checkbox, recipient, title, time) and thenumber you specified.If there are more than one page of emails in the corresponding mailbox, emails on otherpages are displayed when you click “” in the function division.Please note that switching the mailbox view, and clicking “” should load the-onpmsftart 改成 ⽤ n.de appjs_-_--_-_ioennttozfcorresponding email list in the email division without reloading the entire web page.Fig. 2Implement the following to achieve the above functionalities:1. Client Side.1.1 When webmail.html is first loaded, load your specified number of emails in theInbox in the email division, and order them in reverse chronological order. (Hint: register a JSevent onload in the tag)1.2 When a mailbox link in the mailbox division is clicked, retrieve your specifiednumber of the newest emails in the corresponding mailbox from the server side and displaythem in the email division, order them in reverse chronological order, and display thecorresponding function buttons in the function division. (Hint: use the JS event onclick).1.3 Whenever “” is clicked, newer or older emails in the corresponding mailbox(of your specified number) will be retrieved and listed in the email division. (Hint: use the JSevent onclick).1.4 Implement AJAX codes in the event handler functions to communicate with theserver for retrieval of emails from the database.2. Server Side.In app.js, create the following middleware to handle requests from the client side:x HTTP GET requests for http://127.0.0.1:8081/retrieveemaillist. In the middleware,HTMLretrieve information of a number of emails in the respective mailbox from the emailListcollection in the database, according to the request from the client, and send them tothe client (note that only necessary information fo代做COMP3322A、代写NodeJS/Express、Jr the email list display should beretrieved and sent to the client, e.g., the email content is not retrieved/sent). You shoulddecide what data the HTTP request should carry for the server side to retrieve emailsfrom the database accordingly, and the format of the data sent back to the client in theresponse body.Task 3 (15 marks) Display email contentWhen you click each email entry in an email list display (on sender/recipient, title or time), arequest will be sent to the server, which will retrieve the content of the email from theemailList collection in the database, and send it back to the client. The client should displaythe content in the email division, replacing the email list, in the format as shown in Fig. 3.This should not cause reload of the entire web page as well.Fig. 3On this page view, when “” is clicked, the content of the previous (i.e., immediatelynewer) email or the next (i.e., immediately older) email in the same mailbox will be retrievedand displayed. If the current email is the newest one when “when “>” is clicked, the page view remains unchanged.1. Client Side.Similar to Task 2, you should decide the JS events to trigger, implement the correspondingevent handling AJAX code on the client side.按 入 Email ,2. Server Side.In app.js, create the following middleware to handle corresponding requests from the clientside:x HTTP GET requests for http://127.0.0.1:8081/getemail. In the middleware, retrieveinformation of the specific email from the emailList collection in the database, accordingto the request from the client, and send them to the client. You should decide what datathe HTTP request should carry for the server side to retrieve the correct email from thedatabase accordingly, and the format of the data sent back to the client in the responsebody.Task 4 (20 marks) Move emailsTo the left of each email entry in an email list display, there is a checkbox, which you can clickto check and uncheck. When the web page is displaying a particular mailbox view, after youselect some emails in the email list and select an entry in the drop-down list of “Move to …”,a request will be sent to the server to update the “mailbox” field of the corresponding emaildocuments to the selected mailbox correspondingly.After these updates have been successfully done on the server side, the server will furtherretrieve information of Y older emails (if you moved Y emails in the current email list display),and send them to the client. On the client side, you should remove the selected email entriesfrom the email list display in the email division, and append the Y newly retrieved emailentries to the bottom of the list, such that the total number of email entries displayed is stillthe same as before (or smaller only if all older emails have been retrieved). All these shouldnot cause reload of the entire web page as well.On an email content page view as shown in Fig. 3, if you select an entry in the drop-down listof “Move to …”, the current email being displayed should be moved to the selected mailbox,i.e., a request should be sent to the server to update the “mailbox” field of thecorresponding email document to the selected mailbox. Then the page view should go backto the email list display as shown in Fig. 1 or Fig. 2, showing the first page of emails in themailbox which the moved email originally belonged to.1. Client Side.Similar to previous tasks, you should decide the JS event to trigger, and implement the eventhandling AJAX code on the client side.2. Server Side.In app.js, create the following middleware to handle corresponding requests from the clientside:x HTTP POST requests for http://127.0.0.1:8081/changemailbox. In the middleware,update the mailbox field of the corresponding email document(s) in the emailList⽤ POSE 的 ⽅法_response 不⽤ getcollection, according to the request from the client; then retrieve information of emailsaccording to the email list to be generated on the client side, and send them to the client.You should decide what data the request should carry for the server side to update theemail document(s) accordingly, and the format of the data sent back to the client in theresponse body.Task 5 (15 marks) Compose new emailWhen the “Compose” button is clicked, the page view should be as shown in Fig. 4. The “Moveto …”, “” buttons should be disabled on this page view. You can compose a new emailmessage on the page; when “Send” is clicked, a request should be sent to the server side forinserting a new email document into the emailList collection, containing information of the newlycomposed email. Upon receiving success response from the server side, the page view should goback to the email list display as shown in Fig. 1 or Fig. 2, showing the first page of emails inthe mailbox – the one whose email or email list you were viewing before clicking the“Compose” button.Fig. 41. Client Side.Implement the “To” and “Subject” fields using text input boxes and the message content fieldusing . When the “Send” button is clicked, an HTTP post request should be sent to theserver side. Similar to previous tasks, you should decide the JS event to trigger, andimplement the AJAX code on the client side.2. Server Side.In app.js, create the following middleware to handle corresponding requests from the clientside:x HTTP POST requests for http://127.0.0.1:8081/sendemail. In the middleware, insert anew email document into the emailList collection in the database, according to theinformation of the newly composed email carried in the request body. Besides, you canuse the same default sender email address for all composed emails; the “time” in thenew email document should be the current time on the server side; the “mailbox” in thenew email document should be “Sent”. Then retrieve information of emails according tothe email list to be generated on the client side, and send them to the client. You shoulddecide what data the HTTP request should carry for the server side to insert the newemail document accordingly, and the format of the data sent back to the client in theresponse body.Task 6 (10 marks) Style the page using CSSPlease use a separate style.css file to include all your styling rules.1. (5 marks) Use CSS styling you choose to make your page look nice with good layout2. (5 marks) Implement Responsive Web Design to make your page look nice on screens ofdifferent sizes.Notes:1. You can use either basic JavaScript or jQuery to implement client-side scripting.2. Maintain a good programming style: avoid redundant code; the code should be easyto understand and maintain.3. You should carefully test all the functionalities stated in this handout.SubmissionYou should submit the following files in the specified folder structure in a zip file:(1) app.js(2) /public/webmail.html(3) /public/javascripts/script.js(4) /public/stylesheets/style.cssPlease submit the .zip file on Moodle:(1) Login Moodle.(2) Find “Assignments” in the left column and click “Assignment 1”.(3) Click “Add submission”, browse your .zip file and save it. Done.(4) You will receive an automatic confirmation email, if the submission was successful.(5) You can “Edit submission” to your already submitted file, but ONLY before the deadline.转自:http://www.3daixie.com/contents/11/3444.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,287评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,346评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,277评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,132评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,147评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,106评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,019评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,862评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,301评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,521评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,682评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,405评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,996评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,651评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,803评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,674评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,563评论 2 352

推荐阅读更多精彩内容