Skip to content

Commit bc8a690

Browse files
author
Shani
committed
Change code
1 parent 2553870 commit bc8a690

5 files changed

Lines changed: 665 additions & 123 deletions

File tree

Code.gs

Lines changed: 12 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,31 @@
1-
// --- API Endpoints ---
2-
3-
// Handle CORS preflight OPTIONS requests (no custom headers possible)
4-
function doOptions(e) {
5-
// Google Apps Script does not support setting CORS headers for APIs.
6-
// This will just return a 200 OK with a simple JSON body.
7-
return ContentService.createTextOutput(
8-
JSON.stringify({ status: "ok" })
9-
)
10-
.setMimeType(ContentService.MimeType.JSON);
11-
}
12-
13-
// Handle GET requests
14-
function doGet(e) {
15-
let responseData;
16-
try {
17-
const action = e.parameter.action;
18-
19-
// Parse JSON parameters
20-
const params = {};
21-
for (const key in e.parameter) {
22-
if (key !== 'action' && key !== 'callback') {
23-
try {
24-
params[key] = JSON.parse(e.parameter[key]);
25-
} catch (error) {
26-
params[key] = e.parameter[key];
27-
}
28-
}
29-
}
30-
31-
switch (action) {
32-
case 'login':
33-
responseData = loginUser(params.username, params.password);
34-
break;
35-
case 'register':
36-
responseData = registerUser(params.username, params.password);
37-
break;
38-
case 'getTasks':
39-
responseData = getTasks(params.username);
40-
break;
41-
case 'addTask':
42-
responseData = addTask(params.task, params.username);
43-
break;
44-
case 'updateTask':
45-
responseData = updateTask(params.taskId, params.updates, params.username);
46-
break;
47-
case 'getUsers':
48-
responseData = getUsersList();
49-
break;
50-
default:
51-
responseData = { success: false, message: 'Invalid action' };
52-
}
53-
} catch (error) {
54-
responseData = { success: false, message: 'Error: ' + error.toString() };
55-
}
56-
57-
// Handle JSONP callback
58-
const callback = e.parameter.callback;
59-
if (callback) {
60-
return ContentService.createTextOutput(callback + '(' + JSON.stringify(responseData) + ')')
61-
.setMimeType(ContentService.MimeType.JAVASCRIPT);
62-
} else {
63-
return ContentService.createTextOutput(JSON.stringify(responseData))
64-
.setMimeType(ContentService.MimeType.JSON);
65-
}
1+
// --- Main function to serve the web app ---
2+
function doGet() {
3+
return HtmlService.createTemplateFromFile('index')
4+
.evaluate()
5+
.setTitle('Friends Task Manager')
6+
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
667
}
678

68-
// Handle POST requests
69-
function doPost(e) {
70-
let responseData;
71-
try {
72-
const requestData = JSON.parse(e.postData.contents);
73-
const action = requestData.action;
74-
75-
switch (action) {
76-
case 'login':
77-
responseData = loginUser(requestData.username, requestData.password);
78-
break;
79-
case 'register':
80-
responseData = registerUser(requestData.username, requestData.password);
81-
break;
82-
case 'getTasks':
83-
responseData = getTasks(requestData.username);
84-
break;
85-
case 'addTask':
86-
responseData = addTask(requestData.task, requestData.username);
87-
break;
88-
case 'updateTask':
89-
responseData = updateTask(requestData.taskId, requestData.updates, requestData.username);
90-
break;
91-
case 'getUsers':
92-
responseData = getUsersList();
93-
break;
94-
default:
95-
responseData = { success: false, message: 'Invalid action' };
96-
}
97-
} catch (error) {
98-
responseData = { success: false, message: 'Error: ' + error.toString(), stack: error.stack };
99-
}
100-
101-
return ContentService.createTextOutput(JSON.stringify(responseData))
102-
.setMimeType(ContentService.MimeType.JSON);
9+
// --- Include HTML, CSS, JS files ---
10+
function include(filename) {
11+
return HtmlService.createHtmlOutputFromFile(filename).getContent();
10312
}
10413

10514
// --- Configuration ---
106-
const SPREADSHEET_ID = SpreadsheetApp.getActiveSpreadsheet().getId();
10715
const TASKS_SHEET_NAME = "Tasks";
10816
const USERS_SHEET_NAME = "Users";
10917

11018
// --- Helper Functions ---
11119
function getSheet(sheetName) {
112-
return SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName(sheetName);
20+
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
11321
}
11422

11523
function generateUniqueId() {
11624
return Utilities.getUuid();
11725
}
11826

11927
function setupSheetsIfNeeded() {
120-
const ss = SpreadsheetApp.openById(SPREADSHEET_ID);
28+
const ss = SpreadsheetApp.getActiveSpreadsheet();
12129

12230
// Check and create Users sheet if needed
12331
let usersSheet = ss.getSheetByName(USERS_SHEET_NAME);
@@ -187,7 +95,7 @@ function getUsersList() {
18795
}
18896

18997
// --- Task Management ---
190-
function getTasks(username) {
98+
function getTasks() {
19199
setupSheetsIfNeeded();
192100
const tasksSheet = getSheet(TASKS_SHEET_NAME);
193101
if (!tasksSheet) return { success: false, tasks: [], message: 'Tasks sheet not found.' };

README.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A web-based task management application where friends can collaborate on tasks.
1313

1414
## Technology Stack
1515

16-
- Frontend: HTML, CSS, JavaScript (vanilla)
16+
- Frontend: HTML, CSS, JavaScript
1717
- Backend: Google Apps Script
1818
- Database: Google Sheets
1919

@@ -27,8 +27,12 @@ A web-based task management application where friends can collaborate on tasks.
2727
### 2. Set up Google Apps Script
2828

2929
1. In your Google Sheet, click on "Extensions" > "Apps Script"
30-
2. Delete any code in the editor and paste the contents of `Code.gs` from this repository
31-
3. Save the project with a name like "Task Management API"
30+
2. Create the following files in the Apps Script editor:
31+
- `Code.gs`: Copy the content from the Code.gs file in this repository
32+
- `index.html`: Create a new HTML file and copy the content from index.html
33+
- `style.html`: Create a new HTML file and copy the content from style.html
34+
- `script.html`: Create a new HTML file and copy the content from script.html
35+
3. Save the project with a name like "Task Management App"
3236
4. Deploy the project as a web app:
3337
- Click "Deploy" > "New deployment"
3438
- Select type: "Web app"
@@ -37,18 +41,11 @@ A web-based task management application where friends can collaborate on tasks.
3741
- Click "Deploy"
3842
- Copy the web app URL provided after deployment
3943

40-
### 3. Configure the Frontend
44+
### 3. Access Your Application
4145

42-
1. Open `script.js` in a text editor
43-
2. Replace `YOUR_GOOGLE_SCRIPT_ID_HERE` in the `API_URL` constant with your deployed web app URL
44-
45-
### 4. Deploy to GitHub Pages
46-
47-
1. Create a new GitHub repository
48-
2. Upload all files from this project to your repository
49-
3. Go to repository Settings > Pages
50-
4. Select the main branch as the source and click Save
51-
5. Your site will be published at `https://yourusername.github.io/repository-name/`
46+
1. Open the web app URL in your browser
47+
2. Register a new account
48+
3. Start creating and managing tasks
5249

5350
## Usage
5451

@@ -67,10 +64,15 @@ This application uses a simple authentication system and stores passwords in pla
6764

6865
You can customize the application by:
6966

70-
- Modifying the CSS in `style.css` to change the appearance
67+
- Modifying the CSS in `style.html` to change the appearance
7168
- Adding additional fields to tasks by updating the HTML, JavaScript, and Google Apps Script code
7269
- Implementing more advanced features like task comments, file attachments, etc.
7370

74-
## License
71+
## Troubleshooting
72+
73+
If you encounter issues:
7574

76-
This project is available for personal use.
75+
1. Make sure your Google Apps Script deployment is set to "Anyone" for access
76+
2. Check that all HTML files are correctly included in the Apps Script project
77+
3. Verify that the spreadsheet has the correct permissions
78+
4. Check the browser console for any JavaScript errors

index.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>Friends Task Manager</title>
7-
<link rel="stylesheet" href="style.css">
7+
<base target="_top">
8+
<style>
9+
<?!= include('style'); ?>
10+
</style>
811
</head>
912
<body>
1013
<div class="container">
@@ -113,6 +116,8 @@ <h2>Edit Task / Add Solution</h2>
113116
</div>
114117
</div>
115118

116-
<script src="script.js"></script>
119+
<script>
120+
<?!= include('script'); ?>
121+
</script>
117122
</body>
118123
</html>

0 commit comments

Comments
 (0)